Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/routing/Matcher/TraceableUrlMatcher.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 7a779792577d |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
29 | 29 |
30 protected $traces; | 30 protected $traces; |
31 | 31 |
32 public function getTraces($pathinfo) | 32 public function getTraces($pathinfo) |
33 { | 33 { |
34 $this->traces = array(); | 34 $this->traces = []; |
35 | 35 |
36 try { | 36 try { |
37 $this->match($pathinfo); | 37 $this->match($pathinfo); |
38 } catch (ExceptionInterface $e) { | 38 } catch (ExceptionInterface $e) { |
39 } | 39 } |
55 foreach ($routes as $name => $route) { | 55 foreach ($routes as $name => $route) { |
56 $compiledRoute = $route->compile(); | 56 $compiledRoute = $route->compile(); |
57 | 57 |
58 if (!preg_match($compiledRoute->getRegex(), $pathinfo, $matches)) { | 58 if (!preg_match($compiledRoute->getRegex(), $pathinfo, $matches)) { |
59 // does it match without any requirements? | 59 // does it match without any requirements? |
60 $r = new Route($route->getPath(), $route->getDefaults(), array(), $route->getOptions()); | 60 $r = new Route($route->getPath(), $route->getDefaults(), [], $route->getOptions()); |
61 $cr = $r->compile(); | 61 $cr = $r->compile(); |
62 if (!preg_match($cr->getRegex(), $pathinfo)) { | 62 if (!preg_match($cr->getRegex(), $pathinfo)) { |
63 $this->addTrace(sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name, $route); | 63 $this->addTrace(sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name, $route); |
64 | 64 |
65 continue; | 65 continue; |
66 } | 66 } |
67 | 67 |
68 foreach ($route->getRequirements() as $n => $regex) { | 68 foreach ($route->getRequirements() as $n => $regex) { |
69 $r = new Route($route->getPath(), $route->getDefaults(), array($n => $regex), $route->getOptions()); | 69 $r = new Route($route->getPath(), $route->getDefaults(), [$n => $regex], $route->getOptions()); |
70 $cr = $r->compile(); | 70 $cr = $r->compile(); |
71 | 71 |
72 if (in_array($n, $cr->getVariables()) && !preg_match($cr->getRegex(), $pathinfo)) { | 72 if (\in_array($n, $cr->getVariables()) && !preg_match($cr->getRegex(), $pathinfo)) { |
73 $this->addTrace(sprintf('Requirement for "%s" does not match (%s)', $n, $regex), self::ROUTE_ALMOST_MATCHES, $name, $route); | 73 $this->addTrace(sprintf('Requirement for "%s" does not match (%s)', $n, $regex), self::ROUTE_ALMOST_MATCHES, $name, $route); |
74 | 74 |
75 continue 2; | 75 continue 2; |
76 } | 76 } |
77 } | 77 } |
78 | 78 |
79 continue; | 79 continue; |
80 } | 80 } |
81 | 81 |
82 // check host requirement | 82 // check host requirement |
83 $hostMatches = array(); | 83 $hostMatches = []; |
84 if ($compiledRoute->getHostRegex() && !preg_match($compiledRoute->getHostRegex(), $this->context->getHost(), $hostMatches)) { | 84 if ($compiledRoute->getHostRegex() && !preg_match($compiledRoute->getHostRegex(), $this->context->getHost(), $hostMatches)) { |
85 $this->addTrace(sprintf('Host "%s" does not match the requirement ("%s")', $this->context->getHost(), $route->getHost()), self::ROUTE_ALMOST_MATCHES, $name, $route); | 85 $this->addTrace(sprintf('Host "%s" does not match the requirement ("%s")', $this->context->getHost(), $route->getHost()), self::ROUTE_ALMOST_MATCHES, $name, $route); |
86 | 86 |
87 continue; | 87 continue; |
88 } | 88 } |
92 // HEAD and GET are equivalent as per RFC | 92 // HEAD and GET are equivalent as per RFC |
93 if ('HEAD' === $method = $this->context->getMethod()) { | 93 if ('HEAD' === $method = $this->context->getMethod()) { |
94 $method = 'GET'; | 94 $method = 'GET'; |
95 } | 95 } |
96 | 96 |
97 if (!in_array($method, $requiredMethods)) { | 97 if (!\in_array($method, $requiredMethods)) { |
98 $this->allow = array_merge($this->allow, $requiredMethods); | 98 $this->allow = array_merge($this->allow, $requiredMethods); |
99 | 99 |
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); | 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 | 101 |
102 continue; | 102 continue; |
103 } | 103 } |
104 } | 104 } |
105 | 105 |
106 // check condition | 106 // check condition |
107 if ($condition = $route->getCondition()) { | 107 if ($condition = $route->getCondition()) { |
108 if (!$this->getExpressionLanguage()->evaluate($condition, array('context' => $this->context, 'request' => $this->request ?: $this->createRequest($pathinfo)))) { | 108 if (!$this->getExpressionLanguage()->evaluate($condition, ['context' => $this->context, 'request' => $this->request ?: $this->createRequest($pathinfo)])) { |
109 $this->addTrace(sprintf('Condition "%s" does not evaluate to "true"', $condition), self::ROUTE_ALMOST_MATCHES, $name, $route); | 109 $this->addTrace(sprintf('Condition "%s" does not evaluate to "true"', $condition), self::ROUTE_ALMOST_MATCHES, $name, $route); |
110 | 110 |
111 continue; | 111 continue; |
112 } | 112 } |
113 } | 113 } |
129 } | 129 } |
130 } | 130 } |
131 | 131 |
132 private function addTrace($log, $level = self::ROUTE_DOES_NOT_MATCH, $name = null, $route = null) | 132 private function addTrace($log, $level = self::ROUTE_DOES_NOT_MATCH, $name = null, $route = null) |
133 { | 133 { |
134 $this->traces[] = array( | 134 $this->traces[] = [ |
135 'log' => $log, | 135 'log' => $log, |
136 'name' => $name, | 136 'name' => $name, |
137 'level' => $level, | 137 'level' => $level, |
138 'path' => null !== $route ? $route->getPath() : null, | 138 'path' => null !== $route ? $route->getPath() : null, |
139 ); | 139 ]; |
140 } | 140 } |
141 } | 141 } |