Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

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:56 - Dateigröße: 4.97 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\HttpFoundation\Request;
015  use Symfony\Component\Routing\Exception\ExceptionInterface;
016  use Symfony\Component\Routing\Route;
017  use Symfony\Component\Routing\RouteCollection;
018   
019  /**
020   * TraceableUrlMatcher helps debug path info matching by tracing the match.
021   *
022   * @author Fabien Potencier <fabien@symfony.com>
023   */
024  class TraceableUrlMatcher extends UrlMatcher
025  {
026      const ROUTE_DOES_NOT_MATCH = 0;
027      const ROUTE_ALMOST_MATCHES = 1;
028      const ROUTE_MATCHES = 2;
029   
030      protected $traces;
031   
032      public function getTraces($pathinfo)
033      {
034          $this->traces = array();
035   
036          try {
037              $this->match($pathinfo);
038          } catch (ExceptionInterface $e) {
039          }
040   
041          return $this->traces;
042      }
043   
044      public function getTracesForRequest(Request $request)
045      {
046          $this->request = $request;
047          $traces = $this->getTraces($request->getPathInfo());
048          $this->request = null;
049   
050          return $traces;
051      }
052   
053      protected function matchCollection($pathinfo, RouteCollection $routes)
054      {
055          foreach ($routes as $name => $route) {
056              $compiledRoute = $route->compile();
057   
058              if (!preg_match($compiledRoute->getRegex(), $pathinfo, $matches)) {
059                  // does it match without any requirements?
060                  $r = new Route($route->getPath(), $route->getDefaults(), array(), $route->getOptions());
061                  $cr = $r->compile();
062                  if (!preg_match($cr->getRegex(), $pathinfo)) {
063                      $this->addTrace(sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name, $route);
064   
065                      continue;
066                  }
067   
068                  foreach ($route->getRequirements() as $n => $regex) {
069                      $r = new Route($route->getPath(), $route->getDefaults(), array($n => $regex), $route->getOptions());
070                      $cr = $r->compile();
071   
072                      if (in_array($n, $cr->getVariables()) && !preg_match($cr->getRegex(), $pathinfo)) {
073                          $this->addTrace(sprintf('Requirement for "%s" does not match (%s)', $n, $regex), self::ROUTE_ALMOST_MATCHES, $name, $route);
074   
075                          continue 2;
076                      }
077                  }
078   
079                  continue;
080              }
081   
082              // check host requirement
083              $hostMatches = array();
084              if ($compiledRoute->getHostRegex() && !preg_match($compiledRoute->getHostRegex(), $this->context->getHost(), $hostMatches)) {
085                  $this->addTrace(sprintf('Host "%s" does not match the requirement ("%s")', $this->context->getHost(), $route->getHost()), self::ROUTE_ALMOST_MATCHES, $name, $route);
086   
087                  continue;
088              }
089   
090              // check HTTP method requirement
091              if ($requiredMethods = $route->getMethods()) {
092                  // HEAD and GET are equivalent as per RFC
093                  if ('HEAD' === $method = $this->context->getMethod()) {
094                      $method = 'GET';
095                  }
096   
097                  if (!in_array($method, $requiredMethods)) {
098                      $this->allow = array_merge($this->allow, $requiredMethods);
099   
100                      $this->addTrace(sprintf('Method "%s" does not match any of the required methods (%s)', $this->context->getMethod(), implode(', ', $requiredMethods)), self::ROUTE_ALMOST_MATCHES, $name, $route);
101   
102                      continue;
103                  }
104              }
105   
106              // check condition
107              if ($condition = $route->getCondition()) {
108                  if (!$this->getExpressionLanguage()->evaluate($condition, array('context' => $this->context, 'request' => $this->request))) {
109                      $this->addTrace(sprintf('Condition "%s" does not evaluate to "true"', $condition), self::ROUTE_ALMOST_MATCHES, $name, $route);
110   
111                      continue;
112                  }
113              }
114   
115              // check HTTP scheme requirement
116              if ($requiredSchemes = $route->getSchemes()) {
117                  $scheme = $this->context->getScheme();
118   
119                  if (!$route->hasScheme($scheme)) {
120                      $this->addTrace(sprintf('Scheme "%s" does not match any of the required schemes (%s); the user will be redirected to first required scheme', $scheme, implode(', ', $requiredSchemes)), self::ROUTE_ALMOST_MATCHES, $name, $route);
121   
122                      return true;
123                  }
124              }
125   
126              $this->addTrace('Route matches!', self::ROUTE_MATCHES, $name, $route);
127   
128              return true;
129          }
130      }
131   
132      private function addTrace($log, $level = self::ROUTE_DOES_NOT_MATCH, $name = null, $route = null)
133      {
134          $this->traces[] = array(
135              'log' => $log,
136              'name' => $name,
137              'level' => $level,
138              'path' => null !== $route ? $route->getPath() : null,
139          );
140      }
141  }
142