Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/routing/Matcher/UrlMatcher.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 7a779792577d |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
10 */ | 10 */ |
11 | 11 |
12 namespace Symfony\Component\Routing\Matcher; | 12 namespace Symfony\Component\Routing\Matcher; |
13 | 13 |
14 use Symfony\Component\Routing\Exception\MethodNotAllowedException; | 14 use Symfony\Component\Routing\Exception\MethodNotAllowedException; |
15 use Symfony\Component\Routing\Exception\NoConfigurationException; | |
15 use Symfony\Component\Routing\Exception\ResourceNotFoundException; | 16 use Symfony\Component\Routing\Exception\ResourceNotFoundException; |
16 use Symfony\Component\Routing\RouteCollection; | 17 use Symfony\Component\Routing\RouteCollection; |
17 use Symfony\Component\Routing\RequestContext; | 18 use Symfony\Component\Routing\RequestContext; |
18 use Symfony\Component\Routing\Route; | 19 use Symfony\Component\Routing\Route; |
19 use Symfony\Component\HttpFoundation\Request; | 20 use Symfony\Component\HttpFoundation\Request; |
29 { | 30 { |
30 const REQUIREMENT_MATCH = 0; | 31 const REQUIREMENT_MATCH = 0; |
31 const REQUIREMENT_MISMATCH = 1; | 32 const REQUIREMENT_MISMATCH = 1; |
32 const ROUTE_MATCH = 2; | 33 const ROUTE_MATCH = 2; |
33 | 34 |
34 /** | |
35 * @var RequestContext | |
36 */ | |
37 protected $context; | 35 protected $context; |
38 | |
39 /** | |
40 * @var array | |
41 */ | |
42 protected $allow = array(); | 36 protected $allow = array(); |
43 | |
44 /** | |
45 * @var RouteCollection | |
46 */ | |
47 protected $routes; | 37 protected $routes; |
48 | |
49 protected $request; | 38 protected $request; |
50 protected $expressionLanguage; | 39 protected $expressionLanguage; |
51 | 40 |
52 /** | 41 /** |
53 * @var ExpressionFunctionProviderInterface[] | 42 * @var ExpressionFunctionProviderInterface[] |
54 */ | 43 */ |
55 protected $expressionLanguageProviders = array(); | 44 protected $expressionLanguageProviders = array(); |
56 | 45 |
57 /** | |
58 * Constructor. | |
59 * | |
60 * @param RouteCollection $routes A RouteCollection instance | |
61 * @param RequestContext $context The context | |
62 */ | |
63 public function __construct(RouteCollection $routes, RequestContext $context) | 46 public function __construct(RouteCollection $routes, RequestContext $context) |
64 { | 47 { |
65 $this->routes = $routes; | 48 $this->routes = $routes; |
66 $this->context = $context; | 49 $this->context = $context; |
67 } | 50 } |
89 { | 72 { |
90 $this->allow = array(); | 73 $this->allow = array(); |
91 | 74 |
92 if ($ret = $this->matchCollection(rawurldecode($pathinfo), $this->routes)) { | 75 if ($ret = $this->matchCollection(rawurldecode($pathinfo), $this->routes)) { |
93 return $ret; | 76 return $ret; |
77 } | |
78 | |
79 if ('/' === $pathinfo && !$this->allow) { | |
80 throw new NoConfigurationException(); | |
94 } | 81 } |
95 | 82 |
96 throw 0 < count($this->allow) | 83 throw 0 < count($this->allow) |
97 ? new MethodNotAllowedException(array_unique($this->allow)) | 84 ? new MethodNotAllowedException(array_unique($this->allow)) |
98 : new ResourceNotFoundException(sprintf('No routes found for "%s".', $pathinfo)); | 85 : new ResourceNotFoundException(sprintf('No routes found for "%s".', $pathinfo)); |
123 * @param string $pathinfo The path info to be parsed | 110 * @param string $pathinfo The path info to be parsed |
124 * @param RouteCollection $routes The set of routes | 111 * @param RouteCollection $routes The set of routes |
125 * | 112 * |
126 * @return array An array of parameters | 113 * @return array An array of parameters |
127 * | 114 * |
115 * @throws NoConfigurationException If no routing configuration could be found | |
128 * @throws ResourceNotFoundException If the resource could not be found | 116 * @throws ResourceNotFoundException If the resource could not be found |
129 * @throws MethodNotAllowedException If the resource was found but the request method is not allowed | 117 * @throws MethodNotAllowedException If the resource was found but the request method is not allowed |
130 */ | 118 */ |
131 protected function matchCollection($pathinfo, RouteCollection $routes) | 119 protected function matchCollection($pathinfo, RouteCollection $routes) |
132 { | 120 { |
142 continue; | 130 continue; |
143 } | 131 } |
144 | 132 |
145 $hostMatches = array(); | 133 $hostMatches = array(); |
146 if ($compiledRoute->getHostRegex() && !preg_match($compiledRoute->getHostRegex(), $this->context->getHost(), $hostMatches)) { | 134 if ($compiledRoute->getHostRegex() && !preg_match($compiledRoute->getHostRegex(), $this->context->getHost(), $hostMatches)) { |
135 continue; | |
136 } | |
137 | |
138 $status = $this->handleRouteRequirements($pathinfo, $name, $route); | |
139 | |
140 if (self::REQUIREMENT_MISMATCH === $status[0]) { | |
147 continue; | 141 continue; |
148 } | 142 } |
149 | 143 |
150 // check HTTP method requirement | 144 // check HTTP method requirement |
151 if ($requiredMethods = $route->getMethods()) { | 145 if ($requiredMethods = $route->getMethods()) { |
153 if ('HEAD' === $method = $this->context->getMethod()) { | 147 if ('HEAD' === $method = $this->context->getMethod()) { |
154 $method = 'GET'; | 148 $method = 'GET'; |
155 } | 149 } |
156 | 150 |
157 if (!in_array($method, $requiredMethods)) { | 151 if (!in_array($method, $requiredMethods)) { |
158 $this->allow = array_merge($this->allow, $requiredMethods); | 152 if (self::REQUIREMENT_MATCH === $status[0]) { |
153 $this->allow = array_merge($this->allow, $requiredMethods); | |
154 } | |
159 | 155 |
160 continue; | 156 continue; |
161 } | 157 } |
162 } | 158 } |
163 | 159 |
164 $status = $this->handleRouteRequirements($pathinfo, $name, $route); | 160 return $this->getAttributes($route, $name, array_replace($matches, $hostMatches, isset($status[1]) ? $status[1] : array())); |
165 | |
166 if (self::ROUTE_MATCH === $status[0]) { | |
167 return $status[1]; | |
168 } | |
169 | |
170 if (self::REQUIREMENT_MISMATCH === $status[0]) { | |
171 continue; | |
172 } | |
173 | |
174 return $this->getAttributes($route, $name, array_replace($matches, $hostMatches)); | |
175 } | 161 } |
176 } | 162 } |
177 | 163 |
178 /** | 164 /** |
179 * Returns an array of values to use as request attributes. | 165 * Returns an array of values to use as request attributes. |