示例#1
0
 /**
  * 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
  * @param \TYPO3\Fluid\Core\Rendering\RenderingContextInterface $renderingContext
  * @return mixed Value of the property
  */
 public static function getPropertyPath($subject, $propertyPath, \TYPO3\Fluid\Core\Rendering\RenderingContextInterface $renderingContext)
 {
     $propertyPathSegments = explode('.', $propertyPath);
     foreach ($propertyPathSegments as $pathSegment) {
         $propertyExists = FALSE;
         $propertyValue = \TYPO3\Fluid\Reflection\ObjectAccess::getPropertyInternal($subject, $pathSegment, FALSE, $propertyExists);
         if ($propertyExists !== TRUE && (is_array($subject) || $subject instanceof \ArrayAccess) && isset($subject[$pathSegment])) {
             $subject = $subject[$pathSegment];
         } else {
             $subject = $propertyValue;
         }
         if ($subject instanceof \TYPO3\Fluid\Core\Parser\SyntaxTree\RenderingContextAwareInterface) {
             $subject->setRenderingContext($renderingContext);
         }
     }
     return $subject;
 }