Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

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: 02.04.2025, 15:03 - Dateigröße: 6.83 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 = [];
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          // HEAD and GET are equivalent as per RFC
056          if ('HEAD' === $method = $this->context->getMethod()) {
057              $method = 'GET';
058          }
059          $supportsTrailingSlash = '/' !== $pathinfo && '' !== $pathinfo && $this instanceof RedirectableUrlMatcherInterface;
060   
061          foreach ($routes as $name => $route) {
062              $compiledRoute = $route->compile();
063              $staticPrefix = $compiledRoute->getStaticPrefix();
064              $requiredMethods = $route->getMethods();
065   
066              // check the static prefix of the URL first. Only use the more expensive preg_match when it matches
067              if ('' === $staticPrefix || 0 === strpos($pathinfo, $staticPrefix)) {
068                  // no-op
069              } elseif (!$supportsTrailingSlash || ($requiredMethods && !\in_array('GET', $requiredMethods)) || 'GET' !== $method) {
070                  $this->addTrace(sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name, $route);
071                  continue;
072              } elseif ('/' === substr($staticPrefix, -1) && substr($staticPrefix, 0, -1) === $pathinfo) {
073                  $this->addTrace('Route matches!', self::ROUTE_MATCHES, $name, $route);
074   
075                  return $this->allow = [];
076              } else {
077                  $this->addTrace(sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name, $route);
078                  continue;
079              }
080              $regex = $compiledRoute->getRegex();
081   
082              if ($supportsTrailingSlash && $pos = strpos($regex, '/$')) {
083                  $regex = substr($regex, 0, $pos).'/?$'.substr($regex, $pos + 2);
084                  $hasTrailingSlash = true;
085              } else {
086                  $hasTrailingSlash = false;
087              }
088   
089              if (!preg_match($regex, $pathinfo, $matches)) {
090                  // does it match without any requirements?
091                  $r = new Route($route->getPath(), $route->getDefaults(), [], $route->getOptions());
092                  $cr = $r->compile();
093                  if (!preg_match($cr->getRegex(), $pathinfo)) {
094                      $this->addTrace(sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name, $route);
095   
096                      continue;
097                  }
098   
099                  foreach ($route->getRequirements() as $n => $regex) {
100                      $r = new Route($route->getPath(), $route->getDefaults(), [$n => $regex], $route->getOptions());
101                      $cr = $r->compile();
102   
103                      if (\in_array($n, $cr->getVariables()) && !preg_match($cr->getRegex(), $pathinfo)) {
104                          $this->addTrace(sprintf('Requirement for "%s" does not match (%s)', $n, $regex), self::ROUTE_ALMOST_MATCHES, $name, $route);
105   
106                          continue 2;
107                      }
108                  }
109   
110                  continue;
111              }
112   
113              if ($hasTrailingSlash && '/' !== substr($pathinfo, -1)) {
114                  if ((!$requiredMethods || \in_array('GET', $requiredMethods)) && 'GET' === $method) {
115                      $this->addTrace('Route matches!', self::ROUTE_MATCHES, $name, $route);
116   
117                      return $this->allow = [];
118                  }
119                  $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);
120                  continue;
121              }
122   
123              $hostMatches = [];
124              if ($compiledRoute->getHostRegex() && !preg_match($compiledRoute->getHostRegex(), $this->context->getHost(), $hostMatches)) {
125                  $this->addTrace(sprintf('Host "%s" does not match the requirement ("%s")', $this->context->getHost(), $route->getHost()), self::ROUTE_ALMOST_MATCHES, $name, $route);
126                  continue;
127              }
128   
129              $status = $this->handleRouteRequirements($pathinfo, $name, $route);
130   
131              if (self::REQUIREMENT_MISMATCH === $status[0]) {
132                  if ($route->getCondition()) {
133                      $this->addTrace(sprintf('Condition "%s" does not evaluate to "true"', $route->getCondition()), self::ROUTE_ALMOST_MATCHES, $name, $route);
134                  } else {
135                      $this->addTrace(sprintf('Scheme "%s" does not match any of the required schemes (%s); the user will be redirected to first required scheme', $this->getContext()->getScheme(), implode(', ', $route->getSchemes())), self::ROUTE_ALMOST_MATCHES, $name, $route);
136                  }
137   
138                  continue;
139              }
140   
141              // check HTTP method requirement
142              if ($requiredMethods) {
143                  if (!\in_array($method, $requiredMethods)) {
144                      if (self::REQUIREMENT_MATCH === $status[0]) {
145                          $this->allow = array_merge($this->allow, $requiredMethods);
146                      }
147                      $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);
148   
149                      continue;
150                  }
151              }
152   
153              $this->addTrace('Route matches!', self::ROUTE_MATCHES, $name, $route);
154   
155              return $this->getAttributes($route, $name, array_replace($matches, $hostMatches, isset($status[1]) ? $status[1] : []));
156          }
157   
158          return [];
159      }
160   
161      private function addTrace($log, $level = self::ROUTE_DOES_NOT_MATCH, $name = null, $route = null)
162      {
163          $this->traces[] = [
164              'log' => $log,
165              'name' => $name,
166              'level' => $level,
167              'path' => null !== $route ? $route->getPath() : null,
168          ];
169      }
170  }
171