HttpKernelExtension.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. class HttpKernelExtension extends AbstractExtension
  20. {
  21. public function getFunctions()
  22. {
  23. return array(
  24. new TwigFunction('render', array(HttpKernelRuntime::class, 'renderFragment'), array('is_safe' => array('html'))),
  25. new TwigFunction('render_*', array(HttpKernelRuntime::class, 'renderFragmentStrategy'), array('is_safe' => array('html'))),
  26. new TwigFunction('controller', static::class.'::controller'),
  27. );
  28. }
  29. public static function controller($controller, $attributes = array(), $query = array())
  30. {
  31. return new ControllerReference($controller, $attributes, $query);
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public function getName()
  37. {
  38. return 'http_kernel';
  39. }
  40. }