Skip to content

Commit

Permalink
Revert merge of PR #3041
Browse files Browse the repository at this point in the history
This reverts commit 4cdd47d, reversing
changes made to 854c557 in PR #3041.
  • Loading branch information
kdambekalns committed Jun 14, 2024
1 parent 826e920 commit 54a9e1a
Showing 1 changed file with 46 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
* source code.
*/

use Neos\Utility\Exception\PropertyNotAccessibleException;
use Neos\Utility\ObjectAccess;
use Neos\FluidAdaptor\Core\Parser\SyntaxTree\TemplateObjectAccessInterface;
use TYPO3Fluid\Fluid\Core\Variables\StandardVariableProvider;
use TYPO3Fluid\Fluid\Core\Variables\VariableProviderInterface;
Expand All @@ -22,25 +24,27 @@
*/
class TemplateVariableContainer extends StandardVariableProvider implements VariableProviderInterface
{
const ACCESSOR_OBJECT_ACCESS = 'object_access';

/**
* Get a variable by dotted path expression, retrieving the
* variable from nested arrays/objects one segment at a time.
* If the second argument is provided, it must be an array of
* accessor names which can be used to extract each value in
* the dotted path.
*
* @param string $path
* @param array $accessors
* @return mixed
*/
public function getByPath($path)
public function getByPath($path, array $accessors = [])
{
$subject = parent::getByPath($path);
$subject = parent::getByPath($path, $accessors);

if ($subject === null) {
$subject = $this->getBooleanValue($path);
}

if ($subject instanceof TemplateObjectAccessInterface) {
return $subject->objectAccess();
}

return $subject;
}

Expand All @@ -61,6 +65,42 @@ protected function resolveSubVariableReferences(string $propertyPath): string
return $propertyPath;
}

/**
* @param mixed $subject
* @param string $propertyName
* @return NULL|string
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
protected function detectAccessor($subject, $propertyName)
{
return TemplateVariableContainer::ACCESSOR_OBJECT_ACCESS;
}

/**
* @param mixed $subject
* @param string $propertyName
* @param string $accessor
* @return mixed|null
*/
protected function extractWithAccessor($subject, $propertyName, $accessor)
{
if (TemplateVariableContainer::ACCESSOR_OBJECT_ACCESS === $accessor) {
try {
$subject = ObjectAccess::getProperty($subject, $propertyName);
} catch (PropertyNotAccessibleException $e) {
$subject = null;
}
} else {
$subject = parent::extractWithAccessor($subject, $propertyName, $accessor);
}

if ($subject instanceof TemplateObjectAccessInterface) {
return $subject->objectAccess();
}

return $subject;
}

/**
* Tries to interpret the given path as boolean value, either returns the boolean value or null.
*
Expand Down

0 comments on commit 54a9e1a

Please sign in to comment.