DigiComp.FluidRenderFunctions/Classes/Utils/RenderableProxy.php

40 lines
1.1 KiB
PHP
Raw Permalink Normal View History

2024-06-01 23:15:35 +02:00
<?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;
2024-06-01 23:15:35 +02:00
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);
}
}