[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

/vendor/symfony/routing/Symfony/Component/Routing/Matcher/ -> TraceableUrlMatcher.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\ExceptionInterface;
  15  use Symfony\Component\Routing\Route;
  16  use Symfony\Component\Routing\RouteCollection;
  17  
  18  /**
  19   * TraceableUrlMatcher helps debug path info matching by tracing the match.
  20   *
  21   * @author Fabien Potencier <fabien@symfony.com>
  22   */
  23  class TraceableUrlMatcher extends UrlMatcher
  24  {
  25      const ROUTE_DOES_NOT_MATCH = 0;
  26      const ROUTE_ALMOST_MATCHES = 1;
  27      const ROUTE_MATCHES = 2;
  28  
  29      protected $traces;
  30  
  31      public function getTraces($pathinfo)
  32      {
  33          $this->traces = array();
  34  
  35          try {
  36              $this->match($pathinfo);
  37          } catch (ExceptionInterface $e) {
  38          }
  39  
  40          return $this->traces;
  41      }
  42  
  43      protected function matchCollection($pathinfo, RouteCollection $routes)
  44      {
  45          foreach ($routes as $name => $route) {
  46              $compiledRoute = $route->compile();
  47  
  48              if (!preg_match($compiledRoute->getRegex(), $pathinfo, $matches)) {
  49                  // does it match without any requirements?
  50                  $r = new Route($route->getPath(), $route->getDefaults(), array(), $route->getOptions());
  51                  $cr = $r->compile();
  52                  if (!preg_match($cr->getRegex(), $pathinfo)) {
  53                      $this->addTrace(sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name, $route);
  54  
  55                      continue;
  56                  }
  57  
  58                  foreach ($route->getRequirements() as $n => $regex) {
  59                      $r = new Route($route->getPath(), $route->getDefaults(), array($n => $regex), $route->getOptions());
  60                      $cr = $r->compile();
  61  
  62                      if (in_array($n, $cr->getVariables()) && !preg_match($cr->getRegex(), $pathinfo)) {
  63                          $this->addTrace(sprintf('Requirement for "%s" does not match (%s)', $n, $regex), self::ROUTE_ALMOST_MATCHES, $name, $route);
  64  
  65                          continue 2;
  66                      }
  67                  }
  68  
  69                  continue;
  70              }
  71  
  72              // check host requirement
  73              $hostMatches = array();
  74              if ($compiledRoute->getHostRegex() && !preg_match($compiledRoute->getHostRegex(), $this->context->getHost(), $hostMatches)) {
  75                  $this->addTrace(sprintf('Host "%s" does not match the requirement ("%s")', $this->context->getHost(), $route->getHost()), self::ROUTE_ALMOST_MATCHES, $name, $route);
  76  
  77                  continue;
  78              }
  79  
  80              // check HTTP method requirement
  81              if ($req = $route->getRequirement('_method')) {
  82                  // HEAD and GET are equivalent as per RFC
  83                  if ('HEAD' === $method = $this->context->getMethod()) {
  84                      $method = 'GET';
  85                  }
  86  
  87                  if (!in_array($method, $req = explode('|', strtoupper($req)))) {
  88                      $this->allow = array_merge($this->allow, $req);
  89  
  90                      $this->addTrace(sprintf('Method "%s" does not match the requirement ("%s")', $this->context->getMethod(), implode(', ', $req)), self::ROUTE_ALMOST_MATCHES, $name, $route);
  91  
  92                      continue;
  93                  }
  94              }
  95  
  96              // check HTTP scheme requirement
  97              if ($scheme = $route->getRequirement('_scheme')) {
  98                  if ($this->context->getScheme() !== $scheme) {
  99                      $this->addTrace(sprintf('Scheme "%s" does not match the requirement ("%s"); the user will be redirected', $this->context->getScheme(), $scheme), self::ROUTE_ALMOST_MATCHES, $name, $route);
 100  
 101                      return true;
 102                  }
 103              }
 104  
 105              $this->addTrace('Route matches!', self::ROUTE_MATCHES, $name, $route);
 106  
 107              return true;
 108          }
 109      }
 110  
 111      private function addTrace($log, $level = self::ROUTE_DOES_NOT_MATCH, $name = null, $route = null)
 112      {
 113          $this->traces[] = array(
 114              'log' => $log,
 115              'name' => $name,
 116              'level' => $level,
 117              'path' => null !== $route ? $route->getPath() : null,
 118          );
 119      }
 120  }


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