Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

TraceableUrlMatcher.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 4.20 KiB


 001  <?php
 002   
 003  /*
 004   * This file is part of the Symfony package.
 005   *
 006   * (c) Fabien Potencier <fabien@symfony.com>
 007   *
 008   * For the full copyright and license information, please view the LICENSE
 009   * file that was distributed with this source code.
 010   */
 011   
 012  namespace Symfony\Component\Routing\Matcher;
 013   
 014  use Symfony\Component\Routing\Exception\ExceptionInterface;
 015  use Symfony\Component\Routing\Route;
 016  use Symfony\Component\Routing\RouteCollection;
 017   
 018  /**
 019   * TraceableUrlMatcher helps debug path info matching by tracing the match.
 020   *
 021   * @author Fabien Potencier <fabien@symfony.com>
 022   */
 023  class TraceableUrlMatcher extends UrlMatcher
 024  {
 025      const ROUTE_DOES_NOT_MATCH = 0;
 026      const ROUTE_ALMOST_MATCHES = 1;
 027      const ROUTE_MATCHES        = 2;
 028   
 029      protected $traces;
 030   
 031      public function getTraces($pathinfo)
 032      {
 033          $this->traces = array();
 034   
 035          try {
 036              $this->match($pathinfo);
 037          } catch (ExceptionInterface $e) {
 038          }
 039   
 040          return $this->traces;
 041      }
 042   
 043      protected function matchCollection($pathinfo, RouteCollection $routes)
 044      {
 045          foreach ($routes as $name => $route) {
 046              $compiledRoute = $route->compile();
 047   
 048              if (!preg_match($compiledRoute->getRegex(), $pathinfo, $matches)) {
 049                  // does it match without any requirements?
 050                  $r = new Route($route->getPath(), $route->getDefaults(), array(), $route->getOptions());
 051                  $cr = $r->compile();
 052                  if (!preg_match($cr->getRegex(), $pathinfo)) {
 053                      $this->addTrace(sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name, $route);
 054   
 055                      continue;
 056                  }
 057   
 058                  foreach ($route->getRequirements() as $n => $regex) {
 059                      $r = new Route($route->getPath(), $route->getDefaults(), array($n => $regex), $route->getOptions());
 060                      $cr = $r->compile();
 061   
 062                      if (in_array($n, $cr->getVariables()) && !preg_match($cr->getRegex(), $pathinfo)) {
 063                          $this->addTrace(sprintf('Requirement for "%s" does not match (%s)', $n, $regex), self::ROUTE_ALMOST_MATCHES, $name, $route);
 064   
 065                          continue 2;
 066                      }
 067                  }
 068   
 069                  continue;
 070              }
 071   
 072              // check host requirement
 073              $hostMatches = array();
 074              if ($compiledRoute->getHostRegex() && !preg_match($compiledRoute->getHostRegex(), $this->context->getHost(), $hostMatches)) {
 075                  $this->addTrace(sprintf('Host "%s" does not match the requirement ("%s")', $this->context->getHost(), $route->getHost()), self::ROUTE_ALMOST_MATCHES, $name, $route);
 076   
 077                  continue;
 078              }
 079   
 080              // check HTTP method requirement
 081              if ($req = $route->getRequirement('_method')) {
 082                  // HEAD and GET are equivalent as per RFC
 083                  if ('HEAD' === $method = $this->context->getMethod()) {
 084                      $method = 'GET';
 085                  }
 086   
 087                  if (!in_array($method, $req = explode('|', strtoupper($req)))) {
 088                      $this->allow = array_merge($this->allow, $req);
 089   
 090                      $this->addTrace(sprintf('Method "%s" does not match the requirement ("%s")', $this->context->getMethod(), implode(', ', $req)), self::ROUTE_ALMOST_MATCHES, $name, $route);
 091   
 092                      continue;
 093                  }
 094              }
 095   
 096              // check HTTP scheme requirement
 097              if ($scheme = $route->getRequirement('_scheme')) {
 098                  if ($this->context->getScheme() !== $scheme) {
 099                      $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  }
 121