HttpKernelExtension.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 Twig\Extension\AbstractExtension;
  13. use Twig\TwigFunction;
  14. /**
  15. * Provides integration with the HttpKernel component.
  16. *
  17. * @author Fabien Potencier <fabien@symfony.com>
  18. */
  19. final class HttpKernelExtension extends AbstractExtension
  20. {
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public function getFunctions(): array
  25. {
  26. return [
  27. new TwigFunction('render', [HttpKernelRuntime::class, 'renderFragment'], ['is_safe' => ['html']]),
  28. new TwigFunction('render_*', [HttpKernelRuntime::class, 'renderFragmentStrategy'], ['is_safe' => ['html']]),
  29. new TwigFunction('controller', static::class.'::controller'),
  30. ];
  31. }
  32. public static function controller(string $controller, array $attributes = [], array $query = []): ControllerReference
  33. {
  34. return new ControllerReference($controller, $attributes, $query);
  35. }
  36. }