36 lines
896 B
PHP
36 lines
896 B
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
|
||
|
{
|
||
|
$context = new RenderingContext(new DummyView());
|
||
|
$context->getVariableProvider()->add($this->subjectName, $object);
|
||
|
return \trim($this->node->evaluate($context));
|
||
|
}
|
||
|
}
|