[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

/vendor/symfony/routing/Symfony/Component/Routing/Matcher/ -> ApacheUrlMatcher.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\Routing\Matcher;
  13  
  14  use Symfony\Component\Routing\Exception\MethodNotAllowedException;
  15  
  16  /**
  17   * ApacheUrlMatcher matches URL based on Apache mod_rewrite matching (see ApacheMatcherDumper).
  18   *
  19   * @author Fabien Potencier <fabien@symfony.com>
  20   * @author Arnaud Le Blanc <arnaud.lb@gmail.com>
  21   */
  22  class ApacheUrlMatcher extends UrlMatcher
  23  {
  24      /**
  25       * Tries to match a URL based on Apache mod_rewrite matching.
  26       *
  27       * Returns false if no route matches the URL.
  28       *
  29       * @param string $pathinfo The pathinfo to be parsed
  30       *
  31       * @return array An array of parameters
  32       *
  33       * @throws MethodNotAllowedException If the current method is not allowed
  34       */
  35      public function match($pathinfo)
  36      {
  37          $parameters = array();
  38          $defaults = array();
  39          $allow = array();
  40          $route = null;
  41  
  42          foreach ($this->denormalizeValues($_SERVER) as $key => $value) {
  43              $name = $key;
  44  
  45              // skip non-routing variables
  46              // this improves performance when $_SERVER contains many usual
  47              // variables like HTTP_*, DOCUMENT_ROOT, REQUEST_URI, ...
  48              if (false === strpos($name, '_ROUTING_')) {
  49                  continue;
  50              }
  51  
  52              while (0 === strpos($name, 'REDIRECT_')) {
  53                  $name = substr($name, 9);
  54              }
  55  
  56              // expect _ROUTING_<type>_<name>
  57              // or _ROUTING_<type>
  58  
  59              if (0 !== strpos($name, '_ROUTING_')) {
  60                  continue;
  61              }
  62              if (false !== $pos = strpos($name, '_', 9)) {
  63                  $type = substr($name, 9, $pos - 9);
  64                  $name = substr($name, $pos + 1);
  65              } else {
  66                  $type = substr($name, 9);
  67              }
  68  
  69              if ('param' === $type) {
  70                  if ('' !== $value) {
  71                      $parameters[$name] = $value;
  72                  }
  73              } elseif ('default' === $type) {
  74                  $defaults[$name] = $value;
  75              } elseif ('route' === $type) {
  76                  $route = $value;
  77              } elseif ('allow' === $type) {
  78                  $allow[] = $name;
  79              }
  80  
  81              unset($_SERVER[$key]);
  82          }
  83  
  84          if (null !== $route) {
  85              $parameters['_route'] = $route;
  86  
  87              return $this->mergeDefaults($parameters, $defaults);
  88          } elseif (0 < count($allow)) {
  89              throw new MethodNotAllowedException($allow);
  90          } else {
  91              return parent::match($pathinfo);
  92          }
  93      }
  94  
  95      /**
  96       * Denormalizes an array of values.
  97       *
  98       * @param string[] $values
  99       *
 100       * @return array
 101       */
 102      private function denormalizeValues(array $values)
 103      {
 104          $normalizedValues = array();
 105          foreach ($values as $key => $value) {
 106              if (preg_match('~^(.*)\[(\d+)\]$~', $key, $matches)) {
 107                  if (!isset($normalizedValues[$matches[1]])) {
 108                      $normalizedValues[$matches[1]] = array();
 109                  }
 110                  $normalizedValues[$matches[1]][(int) $matches[2]] = $value;
 111              } else {
 112                  $normalizedValues[$key] = $value;
 113              }
 114          }
 115  
 116          return $normalizedValues;
 117      }
 118  }


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