ObjectAccess

Provides methods to call appropriate getter/setter on an object given the property name. It does this following these rules: - if the target object is an instance of ArrayAccess, it gets/sets the property - if public getter/setter method exists, call it.

  • if public property exists, return/set the value of it.
  • else, throw exception
Internal

only to be used within Extbase, not part of TYPO3 Core API.

Table of Contents

Methods

getGettableProperties()  : array<string|int, mixed>
Get all properties (names and their current values) of the current $object that are accessible through this class.
getGettablePropertyNames()  : array<string|int, mixed>
Returns an array of properties which can be get with the getProperty() method.
getProperty()  : mixed
Get a property of a given object.
getPropertyInternal()  : mixed
Gets a property of a given object or array.
getPropertyPath()  : mixed
Gets a property path from a given object or array.
getSettablePropertyNames()  : array<string|int, mixed>
Returns an array of properties which can be set with the setProperty() method.
isPropertyGettable()  : bool
Tells if the value of the specified property can be retrieved by this Object Accessor.
isPropertySettable()  : bool
Tells if the value of the specified property can be set by this Object Accessor.
setProperty()  : bool
Set a property for a given object.

Methods

getGettableProperties()

Get all properties (names and their current values) of the current $object that are accessible through this class.

public static getGettableProperties(object $object) : array<string|int, mixed>
Parameters
$object : object

Object to get all properties from.

Tags
throws
InvalidArgumentException
todo

What to do with ArrayAccess

Return values
array<string|int, mixed>

Associative array of all properties.

getGettablePropertyNames()

Returns an array of properties which can be get with the getProperty() method.

public static getGettablePropertyNames(object $object) : array<string|int, mixed>

Includes the following properties:

  • which can be get through a public getter method.
  • public properties which can be directly get.
Parameters
$object : object

Object to receive property names for

Tags
throws
UnknownClassException
Return values
array<string|int, mixed>

Array of all gettable property names

getProperty()

Get a property of a given object.

public static getProperty(mixed $subject, string $propertyName) : mixed

Tries to get the property the following ways:

  • if the target is an array, and has this property, we call it.
  • if public getter method exists, call it.
  • if the target object is an instance of ArrayAccess, it gets the property on it if it exists.
  • if public property exists, return the value of it.
  • else, throw exception
Parameters
$subject : mixed

Object or array to get the property from

$propertyName : string

name of the property to retrieve

Tags
throws
InvalidArgumentException

in case $subject was not an object or $propertyName was not a string

throws
PropertyNotAccessibleException
Return values
mixed

Value of the property

getPropertyInternal()

Gets a property of a given object or array.

public static getPropertyInternal(mixed $subject, string $propertyName) : mixed

This is an internal method that does only limited type checking for performance reasons. If you can't make sure that $subject is either of type array or object and $propertyName of type string you should use getProperty() instead.

Parameters
$subject : mixed

Object or array to get the property from

$propertyName : string

name of the property to retrieve

Internal
Tags
see
getProperty()
throws
PropertyNotAccessibleException
Return values
mixed

Value of the property

getPropertyPath()

Gets a property path from a given object or array.

public static getPropertyPath(mixed $subject, string $propertyPath) : mixed

If propertyPath is "bla.blubb", then we first call getProperty($object, 'bla'), and on the resulting object we call getProperty(..., 'blubb')

For arrays the keys are checked likewise.

Parameters
$subject : mixed

Object or array to get the property path from

$propertyPath : string
Return values
mixed

Value of the property

getSettablePropertyNames()

Returns an array of properties which can be set with the setProperty() method.

public static getSettablePropertyNames(object $object) : array<string|int, mixed>

Includes the following properties:

  • which can be set through a public setter method.
  • public properties which can be directly set.
Parameters
$object : object

Object to receive property names for

Tags
throws
InvalidArgumentException
Return values
array<string|int, mixed>

Array of all settable property names

isPropertyGettable()

Tells if the value of the specified property can be retrieved by this Object Accessor.

public static isPropertyGettable(object $object, string $propertyName) : bool
Parameters
$object : object

Object containing the property

$propertyName : string

Name of the property to check

Tags
throws
InvalidArgumentException
Return values
bool

isPropertySettable()

Tells if the value of the specified property can be set by this Object Accessor.

public static isPropertySettable(object $object, string $propertyName) : bool
Parameters
$object : object

Object containing the property

$propertyName : string

Name of the property to check

Tags
throws
InvalidArgumentException
Return values
bool

setProperty()

Set a property for a given object.

public static setProperty(mixed &$subject, string $propertyName, mixed $propertyValue) : bool

Tries to set the property the following ways:

  • if target is an array, set value
  • if super cow powers should be used, set value through reflection
  • if public setter method exists, call it.
  • if public property exists, set it directly.
  • if the target object is an instance of ArrayAccess, it sets the property on it without checking if it existed.
  • else, return FALSE
Parameters
$subject : mixed

The target object or array

$propertyName : string

Name of the property to set

$propertyValue : mixed

Value of the property

Tags
throws
InvalidArgumentException

in case $object was not an object or $propertyName was not a string

Return values
bool

TRUE if the property could be set, FALSE otherwise


        
On this page

Search results