2024-06-01 23:15:35 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace DigiComp\FluidRenderFunctions\Utils;
|
|
|
|
|
|
|
|
use DigiComp\FluidRenderFunctions\InvokeRenderFunctionInterface;
|
2024-06-01 23:33:12 +02:00
|
|
|
use Neos\Flow\ObjectManagement\Proxy\ProxyInterface;
|
2024-06-01 23:15:35 +02:00
|
|
|
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
|
|
|
|
{
|
2024-06-01 23:33:12 +02:00
|
|
|
// @deprecated: drop the condition, if compatibility to Flow 6.3 can be dropped
|
|
|
|
$reflector = new \ReflectionClass(RenderingContext::class);
|
|
|
|
if ($reflector->implementsInterface(ProxyInterface::class)) {
|
|
|
|
try {
|
|
|
|
$reflector = new \ReflectionClass($reflector->getParentClass()->getName());
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
// nothing, go with the first one
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$constructor = $reflector->getConstructor();
|
|
|
|
|
|
|
|
if ($constructor->getNumberOfRequiredParameters() > 0) {
|
|
|
|
$context = new RenderingContext(new DummyView());
|
|
|
|
} else {
|
|
|
|
$context = new RenderingContext();
|
|
|
|
}
|
2024-06-01 23:15:35 +02:00
|
|
|
$context->getVariableProvider()->add($this->subjectName, $object);
|
|
|
|
return \trim($this->node->evaluate($context));
|
|
|
|
}
|
|
|
|
}
|