[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/phpbb/routing/ -> helper.php (source)

   1  <?php
   2  /**
   3  *
   4  * This file is part of the phpBB Forum Software package.
   5  *
   6  * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7  * @license GNU General Public License, version 2 (GPL-2.0)
   8  *
   9  * For full copyright and license information, please see
  10  * the docs/CREDITS.txt file.
  11  *
  12  */
  13  
  14  namespace phpbb\routing;
  15  
  16  use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  17  use Symfony\Component\Routing\RequestContext;
  18  
  19  /**
  20  * Controller helper class, contains methods that do things for controllers
  21  */
  22  class helper
  23  {
  24      /**
  25       * config object
  26       * @var \phpbb\config\config
  27       */
  28      protected $config;
  29  
  30      /**
  31       * phpBB router
  32       * @var \phpbb\routing\router
  33       */
  34      protected $router;
  35  
  36      /**
  37       * @var \phpbb\symfony_request
  38       */
  39      protected $symfony_request;
  40  
  41      /**
  42       * @var \phpbb\request\request_interface
  43       */
  44      protected $request;
  45  
  46      /**
  47       * @var \phpbb\filesystem The filesystem object
  48       */
  49      protected $filesystem;
  50  
  51      /**
  52       * phpBB root path
  53       * @var string
  54       */
  55      protected $phpbb_root_path;
  56  
  57      /**
  58       * PHP file extension
  59       * @var string
  60       */
  61      protected $php_ext;
  62  
  63      /**
  64       * Constructor
  65       *
  66       * @param \phpbb\config\config $config Config object
  67       * @param \phpbb\routing\router $router phpBB router
  68       * @param \phpbb\symfony_request $symfony_request Symfony Request object
  69       * @param \phpbb\request\request_interface $request phpBB request object
  70       * @param \phpbb\filesystem\filesystem $filesystem The filesystem object
  71       * @param string $phpbb_root_path phpBB root path
  72       * @param string $php_ext PHP file extension
  73       */
  74  	public function __construct(\phpbb\config\config $config, \phpbb\routing\router $router, \phpbb\symfony_request $symfony_request, \phpbb\request\request_interface $request, \phpbb\filesystem\filesystem $filesystem, $phpbb_root_path, $php_ext)
  75      {
  76          $this->config = $config;
  77          $this->router = $router;
  78          $this->symfony_request = $symfony_request;
  79          $this->request = $request;
  80          $this->filesystem = $filesystem;
  81          $this->phpbb_root_path = $phpbb_root_path;
  82          $this->php_ext = $php_ext;
  83      }
  84  
  85      /**
  86       * Generate a URL to a route
  87       *
  88       * @param string    $route        Name of the route to travel
  89       * @param array    $params        String or array of additional url parameters
  90       * @param bool    $is_amp        Is url using &amp; (true) or & (false)
  91       * @param string|bool        $session_id    Possibility to use a custom session id instead of the global one
  92       * @param bool|string        $reference_type The type of reference to be generated (one of the constants)
  93       * @return string The URL already passed through append_sid()
  94       */
  95  	public function route($route, array $params = array(), $is_amp = true, $session_id = false, $reference_type = UrlGeneratorInterface::ABSOLUTE_PATH)
  96      {
  97          $anchor = '';
  98          if (isset($params['#']))
  99          {
 100              $anchor = '#' . $params['#'];
 101              unset($params['#']);
 102          }
 103  
 104          $context = new RequestContext();
 105          $context->fromRequest($this->symfony_request);
 106  
 107          if ($this->config['force_server_vars'])
 108          {
 109              $context->setHost($this->config['server_name']);
 110              $context->setScheme(substr($this->config['server_protocol'], 0, -3));
 111              $context->setHttpPort($this->config['server_port']);
 112              $context->setHttpsPort($this->config['server_port']);
 113              $context->setBaseUrl(rtrim($this->config['script_path'], '/'));
 114          }
 115  
 116          $script_name = $this->symfony_request->getScriptName();
 117          $page_name = substr($script_name, -1, 1) == '/' ? '' : utf8_basename($script_name);
 118  
 119          $base_url = $context->getBaseUrl();
 120  
 121          // Append page name if base URL does not contain it
 122          if (!empty($page_name) && strpos($base_url, '/' . $page_name) === false)
 123          {
 124              $base_url .= '/' . $page_name;
 125          }
 126  
 127          // If enable_mod_rewrite is false we need to replace the current front-end by app.php, otherwise we need to remove it.
 128          $base_url = str_replace('/' . $page_name, empty($this->config['enable_mod_rewrite']) ? '/app.' . $this->php_ext : '', $base_url);
 129  
 130          // We need to update the base url to move to the directory of the app.php file if the current script is not app.php
 131          if ($page_name !== 'app.php' && !$this->config['force_server_vars'])
 132          {
 133              if (empty($this->config['enable_mod_rewrite']))
 134              {
 135                  $base_url = str_replace('/app.' . $this->php_ext, '/' . $this->phpbb_root_path . 'app.' . $this->php_ext, $base_url);
 136              }
 137              else
 138              {
 139                  $base_url .= preg_replace(get_preg_expression('path_remove_dot_trailing_slash'), '$2', $this->phpbb_root_path);
 140              }
 141          }
 142  
 143          $base_url = $this->request->escape($this->filesystem->clean_path($base_url), true);
 144  
 145          $context->setBaseUrl($base_url);
 146  
 147          $this->router->setContext($context);
 148          $route_url = $this->router->generate($route, $params, $reference_type);
 149  
 150          if ($is_amp)
 151          {
 152              $route_url = str_replace(array('&amp;', '&'), array('&', '&amp;'), $route_url);
 153          }
 154  
 155          if ($reference_type === UrlGeneratorInterface::RELATIVE_PATH && empty($this->config['enable_mod_rewrite']))
 156          {
 157              $route_url = 'app.' . $this->php_ext . '/' . $route_url;
 158          }
 159  
 160          return append_sid($route_url . $anchor, false, $is_amp, $session_id, true);
 161      }
 162  }


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