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: Do proper resolving of FusionPathProxy #3358

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
@@ -1,4 +1,5 @@
<?php

namespace Neos\FluidAdaptor\Core\ViewHelper;

/*
Expand All @@ -13,32 +14,77 @@

use Neos\FluidAdaptor\Core\Parser\SyntaxTree\TemplateObjectAccessInterface;
use TYPO3Fluid\Fluid\Core\Variables\StandardVariableProvider;
use TYPO3Fluid\Fluid\Core\Variables\VariableProviderInterface;

/**
* Provides the variables inside fluid template. Adds TemplateObjectAccessInterface functionality.
*
* @api
*/
class TemplateVariableContainer extends StandardVariableProvider implements VariableProviderInterface
class TemplateVariableContainer extends StandardVariableProvider
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The interface is implemented by the extended class already…

{
/**
* Get a variable by dotted path expression, retrieving the
* variable from nested arrays/objects one segment at a time.
*
* This sadly mostly copies the parent method to add handling for
* subjects of type TemplateObjectAccessInterface.
*
* @param string $path
* @return mixed
*/
public function getByPath($path)
{
$subject = parent::getByPath($path);
// begin copy of parent method
$subject = $this->variables;
$subVariableReferences = explode('.', $this->resolveSubVariableReferences($path));
foreach ($subVariableReferences as $pathSegment) {
// begin TemplateObjectAccessInterface handling
if ($subject instanceof TemplateObjectAccessInterface) {
$subject = $subject->objectAccess();
}
// end TemplateObjectAccessInterface handling
if ((is_array($subject) && array_key_exists($pathSegment, $subject))
|| ($subject instanceof \ArrayAccess && $subject->offsetExists($pathSegment))
) {
$subject = $subject[$pathSegment];
continue;
}
if (is_object($subject)) {
$upperCasePropertyName = ucfirst($pathSegment);
$getMethod = 'get' . $upperCasePropertyName;
if (method_exists($subject, $getMethod)) {
$subject = $subject->$getMethod();
continue;
}
$isMethod = 'is' . $upperCasePropertyName;
if (method_exists($subject, $isMethod)) {
$subject = $subject->$isMethod();
continue;
}
$hasMethod = 'has' . $upperCasePropertyName;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it worth a consideration to use object access here?
And also can it be that we lost certain features over time in fluid like #108?
I cant really judge and am not that invested into it and neither know whats best. But it seems its a bit back and forth ... we seemed to had already such manual implementation once and it got lost it seems?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did very consciously copy the method as unchanged as possible, to make the difference clearly visible and easy to understand. This will make maintenance easier for our future selves.

About #108 – yes, it seems that was lost. But given the decline of Fluid, I have little interest in fixing that nowish, and certainly not in the scope of this PR…

if (method_exists($subject, $hasMethod)) {
$subject = $subject->$hasMethod();
continue;
}
if (property_exists($subject, $pathSegment)) {
$subject = $subject->$pathSegment;
continue;
}
}
// begin TemplateObjectAccessInterface handling
$subject = null;
break;
// end TemplateObjectAccessInterface handling
}
// end copy of parent method

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

// we might still have a TemplateObjectAccessInterface instance
if ($subject instanceof TemplateObjectAccessInterface) {
return $subject->objectAccess();
$subject = $subject->objectAccess();
}

return $subject;
Expand All @@ -63,11 +109,8 @@ protected function resolveSubVariableReferences(string $propertyPath): string

/**
* Tries to interpret the given path as boolean value, either returns the boolean value or null.
*
* @param $path
* @return boolean|null
*/
protected function getBooleanValue($path)
protected function getBooleanValue(string $path): ?bool
{
$normalizedPath = strtolower($path);

Expand Down
Loading