vendor/symfony/twig-bridge/Extension/HttpKernelRuntime.php line 41

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\Bridge\Twig\Extension;
  11. use Symfony\Component\HttpKernel\Controller\ControllerReference;
  12. use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
  13. use Symfony\Component\HttpKernel\Fragment\FragmentUriGeneratorInterface;
  14. /**
  15. * Provides integration with the HttpKernel component.
  16. *
  17. * @author Fabien Potencier <fabien@symfony.com>
  18. */
  19. final class HttpKernelRuntime
  20. {
  21. private $handler;
  22. private $fragmentUriGenerator;
  23. public function __construct(FragmentHandler $handler, ?FragmentUriGeneratorInterface $fragmentUriGenerator = null)
  24. {
  25. $this->handler = $handler;
  26. $this->fragmentUriGenerator = $fragmentUriGenerator;
  27. }
  28. /**
  29. * Renders a fragment.
  30. *
  31. * @param string|ControllerReference $uri A URI as a string or a ControllerReference instance
  32. *
  33. * @see FragmentHandler::render()
  34. */
  35. public function renderFragment($uri, array $options = []): string
  36. {
  37. $strategy = $options['strategy'] ?? 'inline';
  38. unset($options['strategy']);
  39. return $this->handler->render($uri, $strategy, $options);
  40. }
  41. /**
  42. * Renders a fragment.
  43. *
  44. * @param string|ControllerReference $uri A URI as a string or a ControllerReference instance
  45. *
  46. * @see FragmentHandler::render()
  47. */
  48. public function renderFragmentStrategy(string $strategy, $uri, array $options = []): string
  49. {
  50. return $this->handler->render($uri, $strategy, $options);
  51. }
  52. public function generateFragmentUri(ControllerReference $controller, bool $absolute = false, bool $strict = true, bool $sign = true): string
  53. {
  54. if (null === $this->fragmentUriGenerator) {
  55. throw new \LogicException(sprintf('An instance of "%s" must be provided to use "%s()".', FragmentUriGeneratorInterface::class, __METHOD__));
  56. }
  57. return $this->fragmentUriGenerator->generate($controller, null, $absolute, $strict, $sign);
  58. }
  59. }