vendor/symfony/ux-twig-component/src/Twig/ComponentRuntime.php line 51

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\UX\TwigComponent\Twig;
  11. use Symfony\Component\DependencyInjection\ServiceLocator;
  12. use Symfony\UX\TwigComponent\ComponentRenderer;
  13. use Symfony\UX\TwigComponent\Event\PreRenderEvent;
  14. /**
  15. * @author Kevin Bond <kevinbond@gmail.com>
  16. * @author Simon André <smn.andre@gmail.com>
  17. *
  18. * @internal
  19. */
  20. final class ComponentRuntime
  21. {
  22. public function __construct(
  23. private readonly ComponentRenderer $renderer,
  24. private readonly ServiceLocator $renderers,
  25. ) {
  26. }
  27. public function finishEmbedComponent(): void
  28. {
  29. $this->renderer->finishEmbeddedComponentRender();
  30. }
  31. /**
  32. * @param array<string, mixed> $props
  33. */
  34. public function preRender(string $name, array $props): ?string
  35. {
  36. return $this->renderer->preCreateForRender($name, $props);
  37. }
  38. public function render(string $name, array $props = []): string
  39. {
  40. if ($this->renderers->has($normalized = strtolower($name))) {
  41. return $this->renderers->get($normalized)->render($props);
  42. }
  43. return $this->renderer->createAndRender($name, $props);
  44. }
  45. /**
  46. * @param array<string, mixed> $props
  47. * @param array<string, mixed> $context
  48. */
  49. public function startEmbedComponent(string $name, array $props, array $context, string $hostTemplateName, int $index): PreRenderEvent
  50. {
  51. return $this->renderer->startEmbeddedComponentRender($name, $props, $context, $hostTemplateName, $index);
  52. }
  53. }