DigiComp.FluidRenderFunctions/Classes/Utils/RenderableProxy.php

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 = null;
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);
}
}