TYPO3 CMS  TYPO3_6-2
ObjectAccessorNode.php
Go to the documentation of this file.
1 <?php
3 
4 /* *
5  * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6  * *
7  * It is free software; you can redistribute it and/or modify it under *
8  * the terms of the GNU Lesser General Public License, either version 3 *
9  * of the License, or (at your option) any later version. *
10  * *
11  * The TYPO3 project - inspiring people to share! *
12  * */
13 
18 
24  protected $objectPath;
25 
34  public function __construct($objectPath) {
35  $this->objectPath = $objectPath;
36  }
37 
44  public function getObjectPath() {
45  return $this->objectPath;
46  }
47 
62  public function evaluate(\TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext) {
63  return self::getPropertyPath($renderingContext->getTemplateVariableContainer(), $this->objectPath, $renderingContext);
64  }
65 
79  static public function getPropertyPath($subject, $propertyPath, \TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext) {
80  $propertyPathSegments = explode('.', $propertyPath);
81  foreach ($propertyPathSegments as $pathSegment) {
82  $propertyExists = FALSE;
83  $propertyValue = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyInternal($subject, $pathSegment, FALSE, $propertyExists);
84  if ($propertyExists !== TRUE && (is_array($subject) || $subject instanceof \ArrayAccess) && isset($subject[$pathSegment])) {
85  $subject = $subject[$pathSegment];
86  } else {
87  $subject = $propertyValue;
88  }
89 
90  if ($subject instanceof \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RenderingContextAwareInterface) {
91  $subject->setRenderingContext($renderingContext);
92  }
93  }
94  return $subject;
95  }
96 }
static getPropertyInternal($subject, $propertyName, $forceDirectAccess, &$propertyExists)
static getPropertyPath($subject, $propertyPath, \TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext)
evaluate(\TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext)