/** * 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\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext * @return mixed Value of the property */ public static function getPropertyPath($subject, $propertyPath, \TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext) { $propertyPathSegments = explode('.', $propertyPath); foreach ($propertyPathSegments as $pathSegment) { $propertyExists = FALSE; $propertyValue = \TYPO3\CMS\Extbase\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\CMS\Fluid\Core\Parser\SyntaxTree\RenderingContextAwareInterface) { $subject->setRenderingContext($renderingContext); } } return $subject; }
/** * 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\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext * @return mixed Value of the property */ public static function getPropertyPath($subject, $propertyPath, \TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext) { $propertyPathSegments = explode('.', $propertyPath); foreach ($propertyPathSegments as $pathSegment) { if ($subject === null || is_scalar($subject)) { return null; } $propertyExists = false; $propertyValue = \TYPO3\CMS\Extbase\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; } } return $subject; }
public static function parse($subject = null, $propertyPath = '') { if (empty($propertyPath)) { return null; } $propertyPathSegments = explode('.', $propertyPath); if (count($propertyPathSegments) > 0 && !empty($propertyPathSegments[0])) { } foreach ($propertyPathSegments as $pathSegment) { if ($subject === null || is_scalar($subject)) { return null; } $propertyExists = false; $propertyValue = \TYPO3\CMS\Extbase\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; } } return $subject; }