TYPO3 CMS  TYPO3_7-6
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  {
36  $this->objectPath = $objectPath;
37  }
38 
45  public function getObjectPath()
46  {
47  return $this->objectPath;
48  }
49 
64  public function evaluate(\TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext)
65  {
66  return self::getPropertyPath($renderingContext->getTemplateVariableContainer(), $this->objectPath, $renderingContext);
67  }
68 
82  public static function getPropertyPath($subject, $propertyPath, \TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext)
83  {
84  $propertyPathSegments = explode('.', $propertyPath);
85  foreach ($propertyPathSegments as $pathSegment) {
86  if ($subject === null || is_scalar($subject)) {
87  return null;
88  }
89  $propertyExists = false;
90  $propertyValue = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyInternal($subject, $pathSegment, false, $propertyExists);
91  if ($propertyExists !== true && (is_array($subject) || $subject instanceof \ArrayAccess) && isset($subject[$pathSegment])) {
92  $subject = $subject[$pathSegment];
93  } else {
94  $subject = $propertyValue;
95  }
96  }
97  return $subject;
98  }
99 }
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)