DigiComp.FluidRenderFunctions/Classes/Utils/NodeRenderTransfer.php
Ferdinand Kuhl 08b5dd61c7
Some checks failed
ci/woodpecker/push/code-style Pipeline was successful
ci/woodpecker/push/functional-tests/3 Pipeline was successful
ci/woodpecker/push/functional-tests/2 Pipeline was successful
ci/woodpecker/push/functional-tests/1 Pipeline failed
ci/woodpecker/push/functional-tests/4 Pipeline was successful
try to create forward compatibility with Flow 7.x forwards
2024-06-01 23:33:12 +02:00

42 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace DigiComp\FluidRenderFunctions\Utils;
use DigiComp\FluidRenderFunctions\InvokeRenderFunctionInterface;
use Neos\FluidAdaptor\Core\Rendering\RenderingContext;
use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\NodeInterface;
class NodeRenderTransfer implements InvokeRenderFunctionInterface
{
/**
* @var NodeInterface
*/
protected NodeInterface $node;
/**
* @var string
*/
protected string $subjectName;
public function __construct(NodeInterface $node, string $subjectName = 'object')
{
$this->node = $node;
$this->subjectName = $subjectName;
}
public function __invoke($object): string
{
// @deprecated: drop the condition, if compatibility to Flow 6.3 can be dropped
$reflector = new \ReflectionClass(RenderingContext::class);
$constructor = $reflector->getConstructor();
if ($constructor->getNumberOfRequiredParameters() > 0) {
$context = new RenderingContext(new DummyView());
} else {
$context = new RenderingContext();
}
$context->getVariableProvider()->add($this->subjectName, $object);
return \trim($this->node->evaluate($context));
}
}