mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-26 01:23:49 +00:00
Render for generic doc
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\DocStoreBundle\GenericDoc\Twig;
|
||||
|
||||
use Chill\DocStoreBundle\GenericDoc\GenericDocDTO;
|
||||
use Twig\Environment;
|
||||
use Twig\Error\LoaderError;
|
||||
use Twig\Error\RuntimeError;
|
||||
use Twig\Error\SyntaxError;
|
||||
use Twig\Extension\RuntimeExtensionInterface;
|
||||
|
||||
final readonly class GenericDocExtensionRuntime implements RuntimeExtensionInterface
|
||||
{
|
||||
public function __construct(
|
||||
/**
|
||||
* @var list<GenericDocRendererInterface>
|
||||
*/
|
||||
private iterable $renderers,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RuntimeError
|
||||
* @throws SyntaxError
|
||||
* @throws LoaderError
|
||||
*/
|
||||
public function renderGenericDoc(Environment $twig, GenericDocDTO $genericDocDTO, array $options = []): string
|
||||
{
|
||||
foreach ($this->renderers as $renderer) {
|
||||
if ($renderer->supports($genericDocDTO)) {
|
||||
return $twig->render(
|
||||
$renderer->getTemplate($genericDocDTO, $options),
|
||||
$renderer->getTemplateData($genericDocDTO, $options),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
throw new \LogicException("no renderer found");
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user