/** * Evaluate this node and return the correct object. * * Handles each part (denoted by .) in $this->objectPath in the following order: * - call appropriate getter * - call public property, if exists * - fail * * The first part of the object path has to be a variable in the * TemplateVariableContainer. * * @return object The evaluated object, can be any object type. * @author Sebastian Kurfürst <*****@*****.**> * @author Bastian Waidelich <*****@*****.**> * @todo Depending on the context, either fail or not!!! */ public function evaluate() { $objectPathParts = explode('.', $this->objectPath); $variableName = array_shift($objectPathParts); if (!$this->renderingContext->getTemplateVariableContainer()->exists($variableName)) { return NULL; } $currentObject = $this->renderingContext->getTemplateVariableContainer()->get($variableName); if (count($objectPathParts) > 0) { return \F3\FLOW3\Reflection\ObjectAccess::getPropertyPath($currentObject, implode('.', $objectPathParts)); } else { return $currentObject; } }
/** * Get the current property of the object bound to this form. * * @return mixed Value * @author Bastian Waidelich <*****@*****.**> */ protected function getPropertyValue() { $formObject = $this->viewHelperVariableContainer->get('F3\\Fluid\\ViewHelpers\\FormViewHelper', 'formObject'); $propertyName = $this->arguments['property']; if (is_array($formObject)) { return isset($formObject[$propertyName]) ? $formObject[$propertyName] : NULL; } return \F3\FLOW3\Reflection\ObjectAccess::getPropertyPath($formObject, $propertyName); }
/** * @test * @author Karsten Dambekalns <*****@*****.**> */ public function getPropertyPathReturnsNullForNonExistingPropertyPath() { $alternativeObject = new \F3\FLOW3\Tests\Reflection\Fixture\DummyClassWithGettersAndSetters(); $alternativeObject->setProperty(new \stdClass()); $this->dummyObject->setProperty2($alternativeObject); $this->assertNull(\F3\FLOW3\Reflection\ObjectAccess::getPropertyPath($this->dummyObject, 'property2.property.not.existing')); }