Ferdinand Kuhl
b3430789ec
All checks were successful
ci/woodpecker/push/code-style Pipeline was successful
ci/woodpecker/push/functional-tests/2 Pipeline was successful
ci/woodpecker/push/functional-tests/1 Pipeline was successful
ci/woodpecker/push/functional-tests/3 Pipeline was successful
ci/woodpecker/push/functional-tests/4 Pipeline was successful
41 lines
1.4 KiB
PHP
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]+)}/i';
|
|
|
|
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 '';
|
|
}
|
|
}
|