DigiComp.FluidRenderFunctions/Classes/Utils/RenderableProxy.php
Ferdinand Kuhl 0de901d45c
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
First working version
2024-06-01 23:15:35 +02:00

39 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace DigiComp\FluidRenderFunctions\Utils;
use DigiComp\FluidRenderFunctions\InvokeRenderFunctionInterface;
use Neos\Utility\Exception\PropertyNotAccessibleException;
use Neos\Utility\ObjectAccess;
/**
* The RenderableProxy wraps original objects and provides a __toString() function
*
* Because of that, you could use it, to wrap your objects in it and pass the wrapped objects to SelectViewHelper
*/
class RenderableProxy
{
protected InvokeRenderFunctionInterface $renderFunction;
protected $object;
public string $Persistence_Object_Identifier = '';
public function __construct(InvokeRenderFunctionInterface $renderFunction, $object)
{
$this->renderFunction = $renderFunction;
$this->object = $object;
try {
$this->Persistence_Object_Identifier =
ObjectAccess::getProperty($object, 'Persistence_Object_Identifier', true);
} catch (PropertyNotAccessibleException $e) {
// ok. fine
}
}
public function __toString(): string
{
$render = $this->renderFunction;
return $render($this->object);
}
}