/** * 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 Tx_Extbase_Reflection_ObjectAccess::getPropertyPath($currentObject, implode('.', $objectPathParts)); } else { return $currentObject; } }
/** * Get the variable in $name. * * @param string $name * @return mixed */ public function render($name) { if (strpos($name, '.') === FALSE) { if ($this->templateVariableContainer->exists($name) === TRUE) { return $this->templateVariableContainer->get($name); } } else { $segments = explode('.', $name); $templateVariableRootName = array_shift($segments); if ($this->templateVariableContainer->exists($templateVariableRootName)) { $templateVariableRoot = $this->templateVariableContainer->get($templateVariableRootName); try { return Tx_Extbase_Reflection_ObjectAccess::getPropertyPath($templateVariableRoot, implode('.', $segments)); } catch (Exception $e) { return NULL; } } } return NULL; }
/** * Get the current property of the object bound to this form. * * @return mixed Value * @author Bastian Waidelich <*****@*****.**> */ protected function getPropertyValue() { $formObject = $this->viewHelperVariableContainer->get('Tx_Fluid_ViewHelpers_FormViewHelper', 'formObject'); $propertyName = $this->arguments['property']; if (is_array($formObject)) { return isset($formObject[$propertyName]) ? $formObject[$propertyName] : NULL; } return Tx_Extbase_Reflection_ObjectAccess::getPropertyPath($formObject, $propertyName); }
/** * @test */ public function getPropertyPathReturnsNullForNonExistingPropertyPath() { $alternativeObject = new Tx_Extbase_Tests_Unit_Reflection_Fixture_DummyClassWithGettersAndSetters(); $alternativeObject->setProperty(new stdClass()); $this->dummyObject->setProperty2($alternativeObject); $this->assertNull(Tx_Extbase_Reflection_ObjectAccess::getPropertyPath($this->dummyObject, 'property2.property.not.existing')); }
/** * Returns the settings at path $path, which is separated by ".", * e.g. "pages.uid". * "pages.uid" would return $this->settings['pages']['uid']. * * If the path is invalid or no entry is found, false is returned. * * @param string $path * @return mixed */ public function getByPath($path) { return Tx_Extbase_Reflection_ObjectAccess::getPropertyPath($this->getSettings(), $path); }