HttpKernelRuntime.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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\Bridge\Twig\Extension;
  11. use Symfony\Component\HttpKernel\Controller\ControllerReference;
  12. use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
  13. /**
  14. * Provides integration with the HttpKernel component.
  15. *
  16. * @author Fabien Potencier <fabien@symfony.com>
  17. */
  18. final class HttpKernelRuntime
  19. {
  20. private $handler;
  21. public function __construct(FragmentHandler $handler)
  22. {
  23. $this->handler = $handler;
  24. }
  25. /**
  26. * Renders a fragment.
  27. *
  28. * @param string|ControllerReference $uri A URI as a string or a ControllerReference instance
  29. *
  30. * @see FragmentHandler::render()
  31. */
  32. public function renderFragment($uri, array $options = []): string
  33. {
  34. $strategy = $options['strategy'] ?? 'inline';
  35. unset($options['strategy']);
  36. return $this->handler->render($uri, $strategy, $options);
  37. }
  38. /**
  39. * Renders a fragment.
  40. *
  41. * @param string|ControllerReference $uri A URI as a string or a ControllerReference instance
  42. *
  43. * @see FragmentHandler::render()
  44. */
  45. public function renderFragmentStrategy(string $strategy, $uri, array $options = []): string
  46. {
  47. return $this->handler->render($uri, $strategy, $options);
  48. }
  49. }