DigiComp.FluidCurrentContro.../Classes/CurrentControllerExpressionNode.php
Ferdinand Kuhl f75b21a874
Some checks failed
ci/woodpecker/push/code-style Pipeline was successful
ci/woodpecker/push/functional-tests/1 Pipeline failed
ci/woodpecker/push/functional-tests/2 Pipeline failed
ci/woodpecker/push/functional-tests/3 Pipeline failed
ci/woodpecker/push/functional-tests/4 Pipeline failed
changing the format of the expression detections to avoid accidently being identified as objectaccessor and adding a test, where that happend with the previous expression
2024-05-30 15:08:53 +02:00

41 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace DigiComp\FluidCurrentControllerExpression;
use Neos\FluidAdaptor\Core\Rendering\RenderingContext;
use Neos\Utility\ObjectAccess;
use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\Expression\AbstractExpressionNode;
use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\Expression\ExpressionNodeInterface;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
class CurrentControllerExpressionNode extends AbstractExpressionNode implements ExpressionNodeInterface
{
/**
* note: this could be readonly in PHP8
* @var string
*/
public static string $detectionExpression = '/\{#currentController\.([a-z0-9]+)\}/';
public static function evaluateExpression(RenderingContextInterface $renderingContext, $expression, array $matches)
{
if ($renderingContext instanceof RenderingContext) {
$propertyToReturn = $matches[1];
if (
\in_array(
$propertyToReturn,
['actionName', 'name', 'objectName', 'packageKey', 'subpackageKey'],
true
)
) {
$propertyToReturn = 'controller' . \ucfirst($propertyToReturn);
}
return ObjectAccess::getProperty(
$renderingContext->getControllerContext()->getRequest(),
$propertyToReturn
);
}
return '';
}
}