-
-
Notifications
You must be signed in to change notification settings - Fork 187
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
|
||
namespace Neos\FluidAdaptor\Core\ViewHelper; | ||
|
||
/* | ||
|
@@ -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 | ||
{ | ||
/** | ||
* 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it worth a consideration to use object access here? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
@@ -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); | ||
|
||
|
There was a problem hiding this comment.
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…