class ViewLayerData implements IteratorAggregate, Stringable (View source)

This class is used to wrap data before it gets sent to the view layer.

Wrapping data in this class ensures it has consistent escaping and casting applied to it, regardless of what type the original data is.

Traits

A class that can be instantiated or replaced via DI

Constants

META_DATA_NAMES

Special variable names that can be used to get metadata about values

Methods

public static 
create(mixed ...$args)

An implementation of the factory method, allows you to create an instance of a class

public static 
singleton(string $class = null)

Creates a class instance by the "singleton" design pattern.

public
__construct(mixed $data, mixed $source = null, string $name = '')

No description

public
int
getIteratorCount()

Needed so we can rewind in ScopeManager::next() after getting itemIteratorTotal without throwing an exception.

public
getIterator()

No description

public
bool
__isset(string $name)

Checks if a field is set, or if a getter or a method of that name exists.

public
ViewLayerData|null
__get(string $name)

No description

public
ViewLayerData|null
__call(string $name, array $arguments = [])

No description

public
string
__toString()

No description

public
bool
hasDataValue(string|null $name = null, array $arguments = [])

Check if there is a truthy value or (for ModelData) if the data exists().

public
mixed
getRawDataValue(string $name, array $arguments = [])

Get the raw value of some field/property/method on the data, without wrapping it in ViewLayerData.

Details

static Injectable create(mixed ...$args)

An implementation of the factory method, allows you to create an instance of a class

This method will defer class substitution to the Injector API, which can be customised via the Config API to declare substitution classes.

This can be called in one of two ways - either calling via the class directly, or calling on Object and passing the class name as the first parameter. The following are equivalent: $list = DataList::create(SiteTree::class); $list = SiteTree::get();

Parameters

mixed ...$args

Return Value

Injectable

static Injectable singleton(string $class = null)

Creates a class instance by the "singleton" design pattern.

It will always return the same instance for this class, which can be used for performance reasons and as a simple way to access instance methods which don't rely on instance data (e.g. the custom SilverStripe static handling).

Parameters

string $class

Optional classname to create, if the called class should not be used

Return Value

Injectable

The singleton instance

__construct(mixed $data, mixed $source = null, string $name = '')

No description

Parameters

mixed $data
mixed $source

The source of the data

string $name

The name of the field the data comes from, if known

int getIteratorCount()

Needed so we can rewind in ScopeManager::next() after getting itemIteratorTotal without throwing an exception.

Return Value

int

Traversable getIterator()

No description

Return Value

Traversable

bool __isset(string $name)

Checks if a field is set, or if a getter or a method of that name exists.

We need to check each of these, because we don't currently distinguish between a property, a getter, and a method which means if any of those exists we have to say the field is "set", otherwise template engines may skip fetching the data.

Parameters

string $name

Return Value

bool

ViewLayerData|null __get(string $name)

No description

Parameters

string $name

Return Value

ViewLayerData|null

ViewLayerData|null __call(string $name, array $arguments = [])

No description

Parameters

string $name
array $arguments

Return Value

ViewLayerData|null

string __toString()

No description

Return Value

string

bool hasDataValue(string|null $name = null, array $arguments = [])

Check if there is a truthy value or (for ModelData) if the data exists().

If $name is passed, we check for a value in the property/method with that name. Otherwise, check if the currently scoped data has a value.

Parameters

string|null $name
array $arguments

Return Value

bool

mixed getRawDataValue(string $name, array $arguments = [])

Get the raw value of some field/property/method on the data, without wrapping it in ViewLayerData.

Parameters

string $name
array $arguments

Return Value

mixed