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

UrlMatcher.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 5.88 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\MethodNotAllowedException;
015  use Symfony\Component\Routing\Exception\ResourceNotFoundException;
016  use Symfony\Component\Routing\RouteCollection;
017  use Symfony\Component\Routing\RequestContext;
018  use Symfony\Component\Routing\Route;
019   
020  /**
021   * UrlMatcher matches URL based on a set of routes.
022   *
023   * @author Fabien Potencier <fabien@symfony.com>
024   *
025   * @api
026   */
027  class UrlMatcher implements UrlMatcherInterface
028  {
029      const REQUIREMENT_MATCH     = 0;
030      const REQUIREMENT_MISMATCH  = 1;
031      const ROUTE_MATCH           = 2;
032   
033      /**
034       * @var RequestContext
035       */
036      protected $context;
037   
038      /**
039       * @var array
040       */
041      protected $allow = array();
042   
043      /**
044       * @var RouteCollection
045       */
046      protected $routes;
047   
048      /**
049       * Constructor.
050       *
051       * @param RouteCollection $routes  A RouteCollection instance
052       * @param RequestContext  $context The context
053       *
054       * @api
055       */
056      public function __construct(RouteCollection $routes, RequestContext $context)
057      {
058          $this->routes = $routes;
059          $this->context = $context;
060      }
061   
062      /**
063       * {@inheritdoc}
064       */
065      public function setContext(RequestContext $context)
066      {
067          $this->context = $context;
068      }
069   
070      /**
071       * {@inheritdoc}
072       */
073      public function getContext()
074      {
075          return $this->context;
076      }
077   
078      /**
079       * {@inheritdoc}
080       */
081      public function match($pathinfo)
082      {
083          $this->allow = array();
084   
085          if ($ret = $this->matchCollection(rawurldecode($pathinfo), $this->routes)) {
086              return $ret;
087          }
088   
089          throw 0 < count($this->allow)
090              ? new MethodNotAllowedException(array_unique(array_map('strtoupper', $this->allow)))
091              : new ResourceNotFoundException();
092      }
093   
094      /**
095       * Tries to match a URL with a set of routes.
096       *
097       * @param string          $pathinfo The path info to be parsed
098       * @param RouteCollection $routes   The set of routes
099       *
100       * @return array An array of parameters
101       *
102       * @throws ResourceNotFoundException If the resource could not be found
103       * @throws MethodNotAllowedException If the resource was found but the request method is not allowed
104       */
105      protected function matchCollection($pathinfo, RouteCollection $routes)
106      {
107          foreach ($routes as $name => $route) {
108              $compiledRoute = $route->compile();
109   
110              // check the static prefix of the URL first. Only use the more expensive preg_match when it matches
111              if ('' !== $compiledRoute->getStaticPrefix() && 0 !== strpos($pathinfo, $compiledRoute->getStaticPrefix())) {
112                  continue;
113              }
114   
115              if (!preg_match($compiledRoute->getRegex(), $pathinfo, $matches)) {
116                  continue;
117              }
118   
119              $hostMatches = array();
120              if ($compiledRoute->getHostRegex() && !preg_match($compiledRoute->getHostRegex(), $this->context->getHost(), $hostMatches)) {
121                  continue;
122              }
123   
124              // check HTTP method requirement
125              if ($req = $route->getRequirement('_method')) {
126                  // HEAD and GET are equivalent as per RFC
127                  if ('HEAD' === $method = $this->context->getMethod()) {
128                      $method = 'GET';
129                  }
130   
131                  if (!in_array($method, $req = explode('|', strtoupper($req)))) {
132                      $this->allow = array_merge($this->allow, $req);
133   
134                      continue;
135                  }
136              }
137   
138              $status = $this->handleRouteRequirements($pathinfo, $name, $route);
139   
140              if (self::ROUTE_MATCH === $status[0]) {
141                  return $status[1];
142              }
143   
144              if (self::REQUIREMENT_MISMATCH === $status[0]) {
145                  continue;
146              }
147   
148              return $this->getAttributes($route, $name, array_replace($matches, $hostMatches));
149          }
150      }
151   
152      /**
153       * Returns an array of values to use as request attributes.
154       *
155       * As this method requires the Route object, it is not available
156       * in matchers that do not have access to the matched Route instance
157       * (like the PHP and Apache matcher dumpers).
158       *
159       * @param Route  $route      The route we are matching against
160       * @param string $name       The name of the route
161       * @param array  $attributes An array of attributes from the matcher
162       *
163       * @return array An array of parameters
164       */
165      protected function getAttributes(Route $route, $name, array $attributes)
166      {
167          $attributes['_route'] = $name;
168   
169          return $this->mergeDefaults($attributes, $route->getDefaults());
170      }
171   
172      /**
173       * Handles specific route requirements.
174       *
175       * @param string $pathinfo The path
176       * @param string $name     The route name
177       * @param Route  $route    The route
178       *
179       * @return array The first element represents the status, the second contains additional information
180       */
181      protected function handleRouteRequirements($pathinfo, $name, Route $route)
182      {
183          // check HTTP scheme requirement
184          $scheme = $route->getRequirement('_scheme');
185          $status = $scheme && $scheme !== $this->context->getScheme() ? self::REQUIREMENT_MISMATCH : self::REQUIREMENT_MATCH;
186   
187          return array($status, null);
188      }
189   
190      /**
191       * Get merged default parameters.
192       *
193       * @param array $params   The parameters
194       * @param array $defaults The defaults
195       *
196       * @return array Merged default parameters
197       */
198      protected function mergeDefaults($params, $defaults)
199      {
200          foreach ($params as $key => $value) {
201              if (!is_int($key)) {
202                  $defaults[$key] = $value;
203              }
204          }
205   
206          return $defaults;
207      }
208  }
209