[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Fragment/ -> RoutableFragmentRenderer.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\Component\HttpKernel\Fragment;
  13  
  14  use Symfony\Component\HttpKernel\Controller\ControllerReference;
  15  use Symfony\Component\HttpFoundation\Request;
  16  use Symfony\Component\HttpKernel\EventListener\FragmentListener;
  17  
  18  /**
  19   * Adds the possibility to generate a fragment URI for a given Controller.
  20   *
  21   * @author Fabien Potencier <fabien@symfony.com>
  22   */
  23  abstract class RoutableFragmentRenderer implements FragmentRendererInterface
  24  {
  25      private $fragmentPath = '/_fragment';
  26  
  27      /**
  28       * Sets the fragment path that triggers the fragment listener.
  29       *
  30       * @param string $path The path
  31       *
  32       * @see FragmentListener
  33       */
  34      public function setFragmentPath($path)
  35      {
  36          $this->fragmentPath = $path;
  37      }
  38  
  39      /**
  40       * Generates a fragment URI for a given controller.
  41       *
  42       * @param ControllerReference $reference A ControllerReference instance
  43       * @param Request             $request   A Request instance
  44       * @param bool                $absolute  Whether to generate an absolute URL or not
  45       *
  46       * @return string A fragment URI
  47       */
  48      protected function generateFragmentUri(ControllerReference $reference, Request $request, $absolute = false)
  49      {
  50          // We need to forward the current _format and _locale values as we don't have
  51          // a proper routing pattern to do the job for us.
  52          // This makes things inconsistent if you switch from rendering a controller
  53          // to rendering a route if the route pattern does not contain the special
  54          // _format and _locale placeholders.
  55          if (!isset($reference->attributes['_format'])) {
  56              $reference->attributes['_format'] = $request->getRequestFormat();
  57          }
  58          if (!isset($reference->attributes['_locale'])) {
  59              $reference->attributes['_locale'] = $request->getLocale();
  60          }
  61  
  62          $reference->attributes['_controller'] = $reference->controller;
  63  
  64          $reference->query['_path'] = http_build_query($reference->attributes, '', '&');
  65  
  66          $path = $this->fragmentPath.'?'.http_build_query($reference->query, '', '&');
  67  
  68          if ($absolute) {
  69              return $request->getUriForPath($path);
  70          }
  71  
  72          return $request->getBaseUrl().$path;
  73      }
  74  }


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1