Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/routing/Generator/UrlGenerator.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 | 4c8ae668cc8c |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
25 * @author Fabien Potencier <fabien@symfony.com> | 25 * @author Fabien Potencier <fabien@symfony.com> |
26 * @author Tobias Schultze <http://tobion.de> | 26 * @author Tobias Schultze <http://tobion.de> |
27 */ | 27 */ |
28 class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInterface | 28 class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInterface |
29 { | 29 { |
30 /** | |
31 * @var RouteCollection | |
32 */ | |
33 protected $routes; | 30 protected $routes; |
34 | |
35 /** | |
36 * @var RequestContext | |
37 */ | |
38 protected $context; | 31 protected $context; |
39 | 32 |
40 /** | 33 /** |
41 * @var bool|null | 34 * @var bool|null |
42 */ | 35 */ |
43 protected $strictRequirements = true; | 36 protected $strictRequirements = true; |
44 | 37 |
45 /** | |
46 * @var LoggerInterface|null | |
47 */ | |
48 protected $logger; | 38 protected $logger; |
49 | 39 |
50 /** | 40 /** |
51 * This array defines the characters (besides alphanumeric ones) that will not be percent-encoded in the path segment of the generated URL. | 41 * This array defines the characters (besides alphanumeric ones) that will not be percent-encoded in the path segment of the generated URL. |
52 * | 42 * |
73 '%21' => '!', | 63 '%21' => '!', |
74 '%2A' => '*', | 64 '%2A' => '*', |
75 '%7C' => '|', | 65 '%7C' => '|', |
76 ); | 66 ); |
77 | 67 |
78 /** | |
79 * Constructor. | |
80 * | |
81 * @param RouteCollection $routes A RouteCollection instance | |
82 * @param RequestContext $context The context | |
83 * @param LoggerInterface|null $logger A logger instance | |
84 */ | |
85 public function __construct(RouteCollection $routes, RequestContext $context, LoggerInterface $logger = null) | 68 public function __construct(RouteCollection $routes, RequestContext $context, LoggerInterface $logger = null) |
86 { | 69 { |
87 $this->routes = $routes; | 70 $this->routes = $routes; |
88 $this->context = $context; | 71 $this->context = $context; |
89 $this->logger = $logger; | 72 $this->logger = $logger; |
196 } elseif ('/.' === substr($url, -2)) { | 179 } elseif ('/.' === substr($url, -2)) { |
197 $url = substr($url, 0, -1).'%2E'; | 180 $url = substr($url, 0, -1).'%2E'; |
198 } | 181 } |
199 | 182 |
200 $schemeAuthority = ''; | 183 $schemeAuthority = ''; |
201 if ($host = $this->context->getHost()) { | 184 $host = $this->context->getHost(); |
202 $scheme = $this->context->getScheme(); | 185 $scheme = $this->context->getScheme(); |
203 | 186 |
204 if ($requiredSchemes) { | 187 if ($requiredSchemes) { |
205 if (!in_array($scheme, $requiredSchemes, true)) { | 188 if (!in_array($scheme, $requiredSchemes, true)) { |
206 $referenceType = self::ABSOLUTE_URL; | 189 $referenceType = self::ABSOLUTE_URL; |
207 $scheme = current($requiredSchemes); | 190 $scheme = current($requiredSchemes); |
191 } | |
192 } | |
193 | |
194 if ($hostTokens) { | |
195 $routeHost = ''; | |
196 foreach ($hostTokens as $token) { | |
197 if ('variable' === $token[0]) { | |
198 if (null !== $this->strictRequirements && !preg_match('#^'.$token[2].'$#i'.(empty($token[4]) ? '' : 'u'), $mergedParams[$token[3]])) { | |
199 if ($this->strictRequirements) { | |
200 throw new InvalidParameterException(strtr($message, array('{parameter}' => $token[3], '{route}' => $name, '{expected}' => $token[2], '{given}' => $mergedParams[$token[3]]))); | |
201 } | |
202 | |
203 if ($this->logger) { | |
204 $this->logger->error($message, array('parameter' => $token[3], 'route' => $name, 'expected' => $token[2], 'given' => $mergedParams[$token[3]])); | |
205 } | |
206 | |
207 return; | |
208 } | |
209 | |
210 $routeHost = $token[1].$mergedParams[$token[3]].$routeHost; | |
211 } else { | |
212 $routeHost = $token[1].$routeHost; | |
208 } | 213 } |
209 } | 214 } |
210 | 215 |
211 if ($hostTokens) { | 216 if ($routeHost !== $host) { |
212 $routeHost = ''; | 217 $host = $routeHost; |
213 foreach ($hostTokens as $token) { | 218 if (self::ABSOLUTE_URL !== $referenceType) { |
214 if ('variable' === $token[0]) { | 219 $referenceType = self::NETWORK_PATH; |
215 if (null !== $this->strictRequirements && !preg_match('#^'.$token[2].'$#i'.(empty($token[4]) ? '' : 'u'), $mergedParams[$token[3]])) { | |
216 if ($this->strictRequirements) { | |
217 throw new InvalidParameterException(strtr($message, array('{parameter}' => $token[3], '{route}' => $name, '{expected}' => $token[2], '{given}' => $mergedParams[$token[3]]))); | |
218 } | |
219 | |
220 if ($this->logger) { | |
221 $this->logger->error($message, array('parameter' => $token[3], 'route' => $name, 'expected' => $token[2], 'given' => $mergedParams[$token[3]])); | |
222 } | |
223 | |
224 return; | |
225 } | |
226 | |
227 $routeHost = $token[1].$mergedParams[$token[3]].$routeHost; | |
228 } else { | |
229 $routeHost = $token[1].$routeHost; | |
230 } | |
231 } | 220 } |
232 | 221 } |
233 if ($routeHost !== $host) { | 222 } |
234 $host = $routeHost; | 223 |
235 if (self::ABSOLUTE_URL !== $referenceType) { | 224 if ((self::ABSOLUTE_URL === $referenceType || self::NETWORK_PATH === $referenceType) && !empty($host)) { |
236 $referenceType = self::NETWORK_PATH; | 225 $port = ''; |
237 } | 226 if ('http' === $scheme && 80 != $this->context->getHttpPort()) { |
238 } | 227 $port = ':'.$this->context->getHttpPort(); |
239 } | 228 } elseif ('https' === $scheme && 443 != $this->context->getHttpsPort()) { |
240 | 229 $port = ':'.$this->context->getHttpsPort(); |
241 if (self::ABSOLUTE_URL === $referenceType || self::NETWORK_PATH === $referenceType) { | 230 } |
242 $port = ''; | 231 |
243 if ('http' === $scheme && 80 != $this->context->getHttpPort()) { | 232 $schemeAuthority = self::NETWORK_PATH === $referenceType ? '//' : "$scheme://"; |
244 $port = ':'.$this->context->getHttpPort(); | 233 $schemeAuthority .= $host.$port; |
245 } elseif ('https' === $scheme && 443 != $this->context->getHttpsPort()) { | |
246 $port = ':'.$this->context->getHttpsPort(); | |
247 } | |
248 | |
249 $schemeAuthority = self::NETWORK_PATH === $referenceType ? '//' : "$scheme://"; | |
250 $schemeAuthority .= $host.$port; | |
251 } | |
252 } | 234 } |
253 | 235 |
254 if (self::RELATIVE_PATH === $referenceType) { | 236 if (self::RELATIVE_PATH === $referenceType) { |
255 $url = self::getRelativePath($this->context->getPathInfo(), $url); | 237 $url = self::getRelativePath($this->context->getPathInfo(), $url); |
256 } else { | 238 } else { |