Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGFIX: Move access to objectAccess of TemplateObjectAccessInterface into getByPath #3041

Merged
merged 1 commit into from
May 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
* 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 @@ -24,27 +22,25 @@
*/
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, array $accessors = [])
public function getByPath($path)
{
$subject = parent::getByPath($path, $accessors);
$subject = parent::getByPath($path);

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

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

return $subject;
}

Expand All @@ -65,42 +61,6 @@ 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