PropertyAccessorInterface
in
Writes and reads values to/from an object/array graph.
Tags
Table of Contents
Methods
- getValue() : mixed
- Returns the value at the end of the property path of the object graph.
- isReadable() : bool
- Returns whether a property path can be read from an object graph.
- isWritable() : bool
- Returns whether a value can be written at a given property path.
- setValue() : mixed
- Sets the value at the end of the property path of the object graph.
Methods
getValue()
Returns the value at the end of the property path of the object graph.
public
getValue(object|array<string|int, mixed> $objectOrArray, string|PropertyPathInterface $propertyPath) : mixed
Example:
use Symfony\Component\PropertyAccess\PropertyAccess;
$propertyAccessor = PropertyAccess::createPropertyAccessor();
echo $propertyAccessor->getValue($object, 'child.name');
// equals echo $object->getChild()->getName();
This method first tries to find a public getter for each property in the path. The name of the getter must be the camel-cased property name prefixed with "get", "is", or "has".
If the getter does not exist, this method tries to find a public property. The value of the property is then returned.
If none of them are found, an exception is thrown.
Parameters
- $objectOrArray : object|array<string|int, mixed>
- $propertyPath : string|PropertyPathInterface
Tags
isReadable()
Returns whether a property path can be read from an object graph.
public
isReadable(object|array<string|int, mixed> $objectOrArray, string|PropertyPathInterface $propertyPath) : bool
Whenever this method returns true, is guaranteed not to throw an exception when called with the same arguments.
Parameters
- $objectOrArray : object|array<string|int, mixed>
- $propertyPath : string|PropertyPathInterface
Tags
Return values
boolisWritable()
Returns whether a value can be written at a given property path.
public
isWritable(object|array<string|int, mixed> $objectOrArray, string|PropertyPathInterface $propertyPath) : bool
Whenever this method returns true, is guaranteed not to throw an exception when called with the same arguments.
Parameters
- $objectOrArray : object|array<string|int, mixed>
- $propertyPath : string|PropertyPathInterface
Tags
Return values
boolsetValue()
Sets the value at the end of the property path of the object graph.
public
setValue(object|array<string|int, mixed> &$objectOrArray, string|PropertyPathInterface $propertyPath, mixed $value) : mixed
Example:
use Symfony\Component\PropertyAccess\PropertyAccess;
$propertyAccessor = PropertyAccess::createPropertyAccessor();
echo $propertyAccessor->setValue($object, 'child.name', 'Fabien');
// equals echo $object->getChild()->setName('Fabien');
This method first tries to find a public setter for each property in the path. The name of the setter must be the camel-cased property name prefixed with "set".
If the setter does not exist, this method tries to find a public property. The value of the property is then changed.
If neither is found, an exception is thrown.
Parameters
- $objectOrArray : object|array<string|int, mixed>
- $propertyPath : string|PropertyPathInterface
- $value : mixed