Properties

$magicCall

$magicCall : 

Type

$ignoreInvalidIndices

$ignoreInvalidIndices : 

Type

$readPropertyCache

$readPropertyCache : 

Type

$writePropertyCache

$writePropertyCache : 

Type

$previousErrorHandler

$previousErrorHandler : 

Type

$errorHandler

$errorHandler : 

Type

$resultProto

$resultProto : 

Type

Methods

__construct()

__construct(boolean  $magicCall = false, boolean  $throwExceptionOnInvalidIndex = false) 

Should not be used by application code. Use {@link PropertyAccess::createPropertyAccessor()} instead.

Parameters

boolean $magicCall
boolean $throwExceptionOnInvalidIndex

getValue()

getValue(object|array  $objectOrArray, string|\Symfony\Component\PropertyAccess\PropertyPathInterface  $propertyPath) : mixed

Returns the value at the end of the property path of the object graph.

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

object|array $objectOrArray

The object or array to traverse

string|\Symfony\Component\PropertyAccess\PropertyPathInterface $propertyPath

The property path to read

Returns

mixed —

The value at the end of the property path

setValue()

setValue(object|array  $objectOrArray, string|\Symfony\Component\PropertyAccess\PropertyPathInterface  $propertyPath, mixed  $value) 

Sets the value at the end of the property path of the object graph.

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

object|array $objectOrArray

The object or array to modify

string|\Symfony\Component\PropertyAccess\PropertyPathInterface $propertyPath

The property path to modify

mixed $value

The value to set at the end of the property path

isReadable()

isReadable(object|array  $objectOrArray, string|\Symfony\Component\PropertyAccess\PropertyPathInterface  $propertyPath) : boolean

Returns whether a property path can be read from an object graph.

Whenever this method returns true, \Symfony\Component\PropertyAccess\getValue() is guaranteed not to throw an exception when called with the same arguments.

Parameters

object|array $objectOrArray

The object or array to check

string|\Symfony\Component\PropertyAccess\PropertyPathInterface $propertyPath

The property path to check

Returns

boolean —

Whether the property path can be read

isWritable()

isWritable(object|array  $objectOrArray, string|\Symfony\Component\PropertyAccess\PropertyPathInterface  $propertyPath) : boolean

Returns whether a value can be written at a given property path.

Whenever this method returns true, \Symfony\Component\PropertyAccess\setValue() is guaranteed not to throw an exception when called with the same arguments.

Parameters

object|array $objectOrArray

The object or array to check

string|\Symfony\Component\PropertyAccess\PropertyPathInterface $propertyPath

The property path to check

Returns

boolean —

Whether the value can be set

throwInvalidArgumentException()

throwInvalidArgumentException(  $message,   $trace,   $i) 

Parameters

$message
$trace
$i

readPropertiesUntil()

readPropertiesUntil(array  $zval, \Symfony\Component\PropertyAccess\PropertyPathInterface  $propertyPath, integer  $lastIndex, boolean  $ignoreInvalidIndices = true) : array

Reads the path from an object up to a given path index.

Parameters

array $zval

The array containing the object or array to read from

\Symfony\Component\PropertyAccess\PropertyPathInterface $propertyPath

The property path to read

integer $lastIndex

The index up to which should be read

boolean $ignoreInvalidIndices

Whether to ignore invalid indices or throw an exception

Throws

\Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException

if a value within the path is neither object nor array

\Symfony\Component\PropertyAccess\Exception\NoSuchIndexException

If a non-existing index is accessed

Returns

array —

The values read in the path

readIndex()

readIndex(array  $zval, string|integer  $index) : array

Reads a key from an array-like structure.

Parameters

array $zval

The array containing the array or \ArrayAccess object to read from

string|integer $index

The key to read

Throws

\Symfony\Component\PropertyAccess\Exception\NoSuchIndexException

If the array does not implement \ArrayAccess or it is not an array

Returns

array —

The array containing the value of the key

readProperty()

readProperty(array  $zval, string  $property) : array

Reads the a property from an object.

Parameters

array $zval

The array containing the object to read from

string $property

The property to read

Throws

\Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException

if the property does not exist or is not public

Returns

array —

The array containing the value of the property

getReadAccessInfo()

getReadAccessInfo(string  $class, string  $property) : array

Guesses how to read the property value.

Parameters

string $class
string $property

Returns

array

writeIndex()

writeIndex(array  $zval, string|integer  $index, mixed  $value) 

Sets the value of an index in a given array-accessible value.

Parameters

array $zval

The array containing the array or \ArrayAccess object to write to

string|integer $index

The index to write at

mixed $value

The value to write

Throws

\Symfony\Component\PropertyAccess\Exception\NoSuchIndexException

If the array does not implement \ArrayAccess or it is not an array

writeProperty()

writeProperty(array  $zval, string  $property, mixed  $value) 

Sets the value of a property in the given object.

Parameters

array $zval

The array containing the object to write to

string $property

The property to write

mixed $value

The value to write

Throws

\Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException

if the property does not exist or is not public

writeCollection()

writeCollection(array  $zval, string  $property, \Symfony\Component\PropertyAccess\iterable  $collection, string  $addMethod, string  $removeMethod) 

Adjusts a collection-valued property by calling add*() and remove*() methods.

Parameters

array $zval

The array containing the object to write to

string $property

The property to write

\Symfony\Component\PropertyAccess\iterable $collection

The collection to write

string $addMethod

The add*() method

string $removeMethod

The remove*() method

getWriteAccessInfo()

getWriteAccessInfo(string  $class, string  $property, mixed  $value) : array

Guesses how to write the property value.

Parameters

string $class
string $property
mixed $value

Returns

array

isPropertyWritable()

isPropertyWritable(object  $object, string  $property) : boolean

Returns whether a property is writable in the given object.

Parameters

object $object

The object to write to

string $property

The property to write

Returns

boolean —

Whether the property is writable

camelize()

camelize(string  $string) : string

Camelizes a given string.

Parameters

string $string

Some string

Returns

string —

The camelized version of the string

findAdderAndRemover()

findAdderAndRemover(\ReflectionClass  $reflClass, array  $singulars) : array|null

Searches for add and remove methods.

Parameters

\ReflectionClass $reflClass

The reflection class for the given object

array $singulars

The singular form of the property name or null

Returns

array|null —

An array containing the adder and remover when found, null otherwise

isMethodAccessible()

isMethodAccessible(\ReflectionClass  $class, string  $methodName, integer  $parameters) : boolean

Returns whether a method is public and has the number of required parameters.

Parameters

\ReflectionClass $class

The class of the method

string $methodName

The method name

integer $parameters

The number of parameters

Returns

boolean —

Whether the method is public and has $parameters required parameters