Files
kupshop/bundles/KupShop/ComponentsBundle/Utils/ComponentRenderer.php
2025-08-02 16:30:27 +02:00

33 lines
730 B
PHP

<?php
declare(strict_types=1);
namespace KupShop\ComponentsBundle\Utils;
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
use Twig\Environment as Twig;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;
#[Autoconfigure(public: true)]
readonly class ComponentRenderer
{
public function __construct(private Twig $twig)
{
}
/**
* @throws SyntaxError
* @throws LoaderError
* @throws RuntimeError
*/
public function renderToString(string $name, array $data = []): string
{
return $this->twig->render('@Components/components/component.html.twig', [
'name' => $name,
'data' => $data,
]);
}
}