[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/symfony/twig-bridge/Extension/ -> HttpKernelExtension.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the Symfony package.
   5   *
   6   * (c) Fabien Potencier <fabien@symfony.com>
   7   *
   8   * For the full copyright and license information, please view the LICENSE
   9   * file that was distributed with this source code.
  10   */
  11  
  12  namespace Symfony\Bridge\Twig\Extension;
  13  
  14  use Symfony\Component\HttpKernel\Controller\ControllerReference;
  15  use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
  16  use Twig\Extension\AbstractExtension;
  17  use Twig\TwigFunction;
  18  
  19  /**
  20   * Provides integration with the HttpKernel component.
  21   *
  22   * @author Fabien Potencier <fabien@symfony.com>
  23   */
  24  class HttpKernelExtension extends AbstractExtension
  25  {
  26      private $handler;
  27  
  28      public function __construct(FragmentHandler $handler)
  29      {
  30          $this->handler = $handler;
  31      }
  32  
  33      public function getFunctions()
  34      {
  35          return array(
  36              new TwigFunction('render', array($this, 'renderFragment'), array('is_safe' => array('html'))),
  37              new TwigFunction('render_*', array($this, 'renderFragmentStrategy'), array('is_safe' => array('html'))),
  38              new TwigFunction('controller', array($this, 'controller')),
  39          );
  40      }
  41  
  42      /**
  43       * Renders a fragment.
  44       *
  45       * @param string|ControllerReference $uri     A URI as a string or a ControllerReference instance
  46       * @param array                      $options An array of options
  47       *
  48       * @return string The fragment content
  49       *
  50       * @see FragmentHandler::render()
  51       */
  52      public function renderFragment($uri, $options = array())
  53      {
  54          $strategy = isset($options['strategy']) ? $options['strategy'] : 'inline';
  55          unset($options['strategy']);
  56  
  57          return $this->handler->render($uri, $strategy, $options);
  58      }
  59  
  60      /**
  61       * Renders a fragment.
  62       *
  63       * @param string                     $strategy A strategy name
  64       * @param string|ControllerReference $uri      A URI as a string or a ControllerReference instance
  65       * @param array                      $options  An array of options
  66       *
  67       * @return string The fragment content
  68       *
  69       * @see FragmentHandler::render()
  70       */
  71      public function renderFragmentStrategy($strategy, $uri, $options = array())
  72      {
  73          return $this->handler->render($uri, $strategy, $options);
  74      }
  75  
  76      public function controller($controller, $attributes = array(), $query = array())
  77      {
  78          return new ControllerReference($controller, $attributes, $query);
  79      }
  80  
  81      /**
  82       * {@inheritdoc}
  83       */
  84      public function getName()
  85      {
  86          return 'http_kernel';
  87      }
  88  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1