/** * 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. * * @param mixed $subject An object or array * @param string $propertyPath * @return mixed Value of the property */ protected function getPropertyPath($subject, $propertyPath, Tx_Fluid_Core_Rendering_RenderingContextInterface $renderingContext) { $propertyPathSegments = explode('.', $propertyPath); foreach ($propertyPathSegments as $pathSegment) { if (is_object($subject) && Tx_Extbase_Reflection_ObjectAccess::isPropertyGettable($subject, $pathSegment)) { $subject = Tx_Extbase_Reflection_ObjectAccess::getProperty($subject, $pathSegment); } elseif ((is_array($subject) || $subject instanceof ArrayAccess) && isset($subject[$pathSegment])) { $subject = $subject[$pathSegment]; } else { return NULL; } if ($subject instanceof Tx_Fluid_Core_Parser_SyntaxTree_RenderingContextAwareInterface) { $subject->setRenderingContext($renderingContext); } } return $subject; }
/** * @test */ public function isPropertyGettableWorksOnStdClass() { $stdClassObject = new stdClass(); $stdClassObject->property = 'foo'; $this->assertTrue(Tx_Extbase_Reflection_ObjectAccess::isPropertyGettable($stdClassObject, 'property')); $this->assertFalse(Tx_Extbase_Reflection_ObjectAccess::isPropertyGettable($stdClassObject, 'undefinedProperty')); }