‪TYPO3CMS  10.4
TYPO3\CMS\Extbase\Reflection\ObjectAccess Class Reference

Static Public Member Functions

static mixed getProperty ($subject, string $propertyName, bool $forceDirectAccess=false)
 
static mixed getPropertyInternal ($subject, string $propertyName, bool $forceDirectAccess=false)
 
static mixed getPropertyPath ($subject, string $propertyPath)
 
static bool setProperty (&$subject, string $propertyName, $propertyValue, bool $forceDirectAccess=false)
 
static array getGettablePropertyNames (object $object)
 
static array getSettablePropertyNames (object $object)
 
static bool isPropertySettable (object $object, $propertyName)
 
static bool isPropertyGettable ($object, $propertyName)
 
static array getGettableProperties (object $object)
 
static string buildSetterMethodName ($propertyName)
 

Static Private Member Functions

static PropertyAccessor createAccessor ()
 
static mixed getObjectPropertyValue (object $subject, PropertyPath $propertyPath, bool $forceDirectAccess)
 
static mixed getArrayIndexValue (array $subject, PropertyPath $propertyPath)
 
static PropertyPath convertToArrayPropertyPath (PropertyPath $propertyPath)
 
static string wrap (string $segment)
 

Static Private Attributes

static PropertyAccessor $propertyAccessor
 

Detailed Description

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

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

Definition at line 37 of file ObjectAccess.php.

Member Function Documentation

◆ buildSetterMethodName()

static string TYPO3\CMS\Extbase\Reflection\ObjectAccess::buildSetterMethodName (   $propertyName)
static

Build the setter method name for a given property by capitalizing the first letter of the property, and prepending it with "set".

Parameters
string$propertyName‪Name of the property
Returns
‪string Name of the setter method name
Deprecated:

Definition at line 374 of file ObjectAccess.php.

◆ convertToArrayPropertyPath()

static PropertyPath TYPO3\CMS\Extbase\Reflection\ObjectAccess::convertToArrayPropertyPath ( PropertyPath  $propertyPath)
staticprivate
Parameters
PropertyPath$propertyPath
Returns
‪PropertyPath

Definition at line 439 of file ObjectAccess.php.

Referenced by TYPO3\CMS\Extbase\Reflection\ObjectAccess\getPropertyInternal().

◆ createAccessor()

static PropertyAccessor TYPO3\CMS\Extbase\Reflection\ObjectAccess::createAccessor ( )
staticprivate

◆ getArrayIndexValue()

static mixed TYPO3\CMS\Extbase\Reflection\ObjectAccess::getArrayIndexValue ( array  $subject,
PropertyPath  $propertyPath 
)
staticprivate
Parameters
array$subject
PropertyPath$propertyPath
Returns
‪mixed

Definition at line 430 of file ObjectAccess.php.

Referenced by TYPO3\CMS\Extbase\Reflection\ObjectAccess\getPropertyInternal().

◆ getGettableProperties()

static array TYPO3\CMS\Extbase\Reflection\ObjectAccess::getGettableProperties ( object  $object)
static

◆ getGettablePropertyNames()

static array TYPO3\CMS\Extbase\Reflection\ObjectAccess::getGettablePropertyNames ( object  $object)
static

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

  • ‪which can be get through a public getter method.
  • ‪public properties which can be directly get.
Parameters
object$objectObject to receive property names for
Returns
‪array Array of all gettable property names
Exceptions
Exception

Definition at line 217 of file ObjectAccess.php.

References TYPO3\CMS\Core\Utility\StringUtility\beginsWith().

Referenced by TYPO3\CMS\Extbase\Tests\Unit\Reflection\ObjectAccessTest\getGettablePropertyNamesRespectsMethodArguments(), TYPO3\CMS\Extbase\Tests\Unit\Reflection\ObjectAccessTest\getGettablePropertyNamesReturnsAllPropertiesWhichAreAvailable(), and TYPO3\CMS\Extbase\Mvc\View\JsonView\transformObject().

◆ getObjectPropertyValue()

static mixed TYPO3\CMS\Extbase\Reflection\ObjectAccess::getObjectPropertyValue ( object  $subject,
PropertyPath  $propertyPath,
bool  $forceDirectAccess 
)
staticprivate
Parameters
object$subject
PropertyPath$propertyPath
bool$forceDirectAccess
Returns
‪mixed
Exceptions
Exception

Definition at line 402 of file ObjectAccess.php.

Referenced by TYPO3\CMS\Extbase\Reflection\ObjectAccess\getPropertyInternal().

◆ getProperty()

static mixed TYPO3\CMS\Extbase\Reflection\ObjectAccess::getProperty (   $subject,
string  $propertyName,
bool  $forceDirectAccess = false 
)
static

Get a property of a given object. Tries to get the property the following ways:

  • ‪if the target is an array, and has this property, we call it.
  • ‪if super cow powers should be used, fetch value through reflection
  • ‪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
mixed$subjectObject or array to get the property from
string$propertyName‪name of the property to retrieve
bool$forceDirectAccess‪directly access property using reflection(!)
Exceptions

Definition at line 62 of file ObjectAccess.php.

References TYPO3\CMS\Extbase\Reflection\ObjectAccess\getPropertyInternal().

Referenced by TYPO3\CMS\Fluid\ViewHelpers\Widget\Controller\AutocompleteController\autocompleteAction(), TYPO3\CMS\Extbase\Persistence\Generic\Backend\determineStoragePageIdForNewRecord(), TYPO3\CMS\Extbase\Tests\Unit\Reflection\ObjectAccessTest\getPropertyCanAccessPropertiesOfAnArray(), TYPO3\CMS\Extbase\Tests\Unit\Reflection\ObjectAccessTest\getPropertyCanAccessPropertiesOfAnArrayObject(), TYPO3\CMS\Extbase\Tests\Unit\Reflection\ObjectAccessTest\getPropertyCanAccessPropertiesOfAnObjectImplementingArrayAccess(), TYPO3\CMS\Extbase\Tests\Unit\Reflection\ObjectAccessTest\getPropertyCanAccessPropertiesOfAnObjectStorageObject(), TYPO3\CMS\Extbase\Tests\Unit\Reflection\ObjectAccessTest\getPropertyCanAccessPropertiesOfArrayAccessWithGetterMethodWhenOffsetNotExists(), TYPO3\CMS\Extbase\Tests\Unit\Reflection\ObjectAccessTest\getPropertyCanAccessPropertiesOfArrayAccessWithPriorityForOffsetIfOffsetExists(), TYPO3\CMS\Extbase\Tests\Unit\Reflection\ObjectAccessTest\getPropertyReturnsExpectedValueForGetterProperty(), TYPO3\CMS\Extbase\Tests\Unit\Reflection\ObjectAccessTest\getPropertyReturnsExpectedValueForPublicProperty(), TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\ObjectAccessTest\getPropertyReturnsExpectedValueForUnexposedPropertyIfForceDirectAccessIsTrue(), TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\ObjectAccessTest\getPropertyReturnsExpectedValueForUnknownPropertyIfForceDirectAccessIsTrue(), TYPO3\CMS\Extbase\Tests\Unit\Reflection\ObjectAccessTest\getPropertyReturnsNullIfArrayKeyDoesNotExist(), TYPO3\CMS\Extbase\Tests\Unit\Reflection\ObjectAccessTest\getPropertyThrowsExceptionIfPropertyDoesNotExist(), TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\ObjectAccessTest\getPropertyThrowsPropertyNotAccessibleExceptionForNotExistingPropertyIfForceDirectAccessIsTrue(), TYPO3\CMS\Extbase\Tests\Unit\Reflection\ObjectAccessTest\getPropertyTriesToCallABooleanGetterMethodIfItExists(), TYPO3\CMS\Extbase\Validation\Validator\GenericObjectValidator\getPropertyValue(), and TYPO3\CMS\Extbase\Mvc\View\JsonView\transformObject().

◆ getPropertyInternal()

static mixed TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyInternal (   $subject,
string  $propertyName,
bool  $forceDirectAccess = false 
)
static

Gets a property of a given object or array. 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.

See also
getProperty()
Parameters
mixed$subjectObject or array to get the property from
string$propertyName‪name of the property to retrieve
bool$forceDirectAccess‪directly access property using reflection(!)
Exceptions
Exception

Definition at line 89 of file ObjectAccess.php.

References TYPO3\CMS\Extbase\Reflection\ObjectAccess\convertToArrayPropertyPath(), TYPO3\CMS\Extbase\Reflection\ObjectAccess\createAccessor(), TYPO3\CMS\Extbase\Reflection\ObjectAccess\getArrayIndexValue(), and TYPO3\CMS\Extbase\Reflection\ObjectAccess\getObjectPropertyValue().

Referenced by TYPO3\CMS\Extbase\Reflection\ObjectAccess\getProperty(), TYPO3\CMS\Extbase\Reflection\ObjectAccess\getPropertyPath(), and TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataTest\getPropertyPath().

◆ getPropertyPath()

static mixed TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath (   $subject,
string  $propertyPath 
)
static

Gets a property path from a given object or array.

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
mixed$subjectObject or array to get the property path from
string$propertyPath
Returns
‪mixed Value of the property

Definition at line 139 of file ObjectAccess.php.

References TYPO3\CMS\Extbase\Reflection\ObjectAccess\getPropertyInternal().

Referenced by TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper\addAdditionalIdentityPropertiesIfNeeded(), TYPO3\CMS\Form\Domain\Model\FormDefinition\getElementDefaultValueByIdentifier(), TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper\getLastSubmittedFormData(), TYPO3\CMS\Fluid\ViewHelpers\Form\SelectViewHelper\getOptions(), TYPO3\CMS\Fluid\ViewHelpers\Form\SelectViewHelper\getOptionValueScalar(), TYPO3\CMS\Extbase\Tests\Unit\Reflection\ObjectAccessTest\getPropertyPathCanAccessPropertiesOfAnArray(), TYPO3\CMS\Extbase\Tests\Unit\Reflection\ObjectAccessTest\getPropertyPathCanAccessPropertiesOfAnExtbaseObjectStorageObject(), TYPO3\CMS\Extbase\Tests\Unit\Reflection\ObjectAccessTest\getPropertyPathCanAccessPropertiesOfAnObjectImplementingArrayAccess(), TYPO3\CMS\Extbase\Tests\Unit\Reflection\ObjectAccessTest\getPropertyPathCanAccessPropertiesOfAnSplObjectStorageObject(), TYPO3\CMS\Extbase\Tests\Unit\Reflection\ObjectAccessTest\getPropertyPathCanRecursivelyGetPropertiesOfAnObject(), TYPO3\CMS\Extbase\Tests\Unit\Reflection\ObjectAccessTest\getPropertyPathOnObjectStorageDoesNotAffectOngoingLoop(), TYPO3\CMS\Extbase\Tests\Unit\Reflection\ObjectAccessTest\getPropertyPathOnSplObjectStorageDoesNotAffectOngoingLoop(), TYPO3\CMS\Extbase\Tests\Unit\Reflection\ObjectAccessTest\getPropertyPathReturnsNullForNonExistingPropertyPath(), TYPO3\CMS\Extbase\Tests\Unit\Reflection\ObjectAccessTest\getPropertyPathReturnsNullIfSubjectIsNoObject(), TYPO3\CMS\Extbase\Tests\Unit\Reflection\ObjectAccessTest\getPropertyPathReturnsNullIfSubjectOnPathIsNoObject(), TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper\getPropertyValue(), and TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher\resolveRuntimeReference().

◆ getSettablePropertyNames()

static array TYPO3\CMS\Extbase\Reflection\ObjectAccess::getSettablePropertyNames ( object  $object)
static

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

  • ‪which can be set through a public setter method.
  • ‪public properties which can be directly set.
Parameters
object$objectObject to receive property names for
Exceptions

Definition at line 277 of file ObjectAccess.php.

References TYPO3\CMS\Core\Utility\StringUtility\beginsWith(), and TYPO3\CMS\Extbase\function.

Referenced by TYPO3\CMS\Extbase\Tests\Unit\Reflection\ObjectAccessTest\getSettablePropertyNamesReturnsAllPropertiesWhichAreAvailable(), and TYPO3\CMS\Extbase\Tests\Unit\Reflection\ObjectAccessTest\getSettablePropertyNamesReturnsPropertyNamesOfStdClass().

◆ isPropertyGettable()

static bool TYPO3\CMS\Extbase\Reflection\ObjectAccess::isPropertyGettable (   $object,
  $propertyName 
)
static

◆ isPropertySettable()

static bool TYPO3\CMS\Extbase\Reflection\ObjectAccess::isPropertySettable ( object  $object,
  $propertyName 
)
static

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

Parameters
object$objectObject containing the property
string$propertyName‪Name of the property to check
Exceptions

Definition at line 313 of file ObjectAccess.php.

Referenced by TYPO3\CMS\Extbase\Tests\Unit\Reflection\ObjectAccessTest\isPropertySettableTellsIfAPropertyCanBeSet(), and TYPO3\CMS\Extbase\Tests\Unit\Reflection\ObjectAccessTest\isPropertySettableWorksOnStdClass().

◆ setProperty()

static bool TYPO3\CMS\Extbase\Reflection\ObjectAccess::setProperty ( $subject,
string  $propertyName,
  $propertyValue,
bool  $forceDirectAccess = false 
)
static

Set a property for a given object. 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
mixed$subject‪The target object or array
string$propertyName‪Name of the property to set
mixed$propertyValue‪Value of the property
bool$forceDirectAccess‪directly access property using reflection(!)
Exceptions

Definition at line 170 of file ObjectAccess.php.

References TYPO3\CMS\Extbase\Reflection\ObjectAccess\createAccessor().

Referenced by TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter\convertFrom(), TYPO3\CMS\Extbase\Property\TypeConverter\ObjectConverter\convertFrom(), TYPO3\CMS\Extbase\Tests\Unit\Reflection\ObjectAccessTest\setPropertyCallsASetterMethodToSetThePropertyValueIfOneIsAvailable(), TYPO3\CMS\Extbase\Tests\Unit\Reflection\ObjectAccessTest\setPropertyCanDirectlySetValuesInAnArrayObjectOrArray(), TYPO3\CMS\Extbase\Tests\Unit\Reflection\ObjectAccessTest\setPropertyReturnsFalseIfPropertyIsNotAccessible(), and TYPO3\CMS\Extbase\Tests\Unit\Reflection\ObjectAccessTest\setPropertyWorksWithPublicProperty().

◆ wrap()

static string TYPO3\CMS\Extbase\Reflection\ObjectAccess::wrap ( string  $segment)
staticprivate
Parameters
string$segment
Returns
‪string

Definition at line 452 of file ObjectAccess.php.

Member Data Documentation

◆ $propertyAccessor

PropertyAccessor TYPO3\CMS\Extbase\Reflection\ObjectAccess::$propertyAccessor
staticprivate

Definition at line 41 of file ObjectAccess.php.