Skip to content

Commit 1716997

Browse files
Merge branch '4.2' into 4.3
* 4.2: [Routing] Fixed unexpected 404 NoConfigurationException [DI] Removes number of elements information in debug mode [Contracts] Simplify implementation declarations Update PR template for 4.3 [Intl] Add FallbackTrait for data generation [Console] Commands with an alias should not be recognized as ambiguous clarify the possible class/interface of the cache
2 parents 82fac7d + 221b839 commit 1716997

File tree

3 files changed

+16
-27
lines changed

3 files changed

+16
-27
lines changed

Matcher/Dumper/CompiledUrlMatcherTrait.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function match($pathinfo)
4242
throw new MethodNotAllowedException(array_keys($allow));
4343
}
4444
if (!$this instanceof RedirectableUrlMatcherInterface) {
45-
throw new ResourceNotFoundException();
45+
throw new ResourceNotFoundException(sprintf('No routes found for "%s".', $pathinfo));
4646
}
4747
if (!\in_array($this->context->getMethod(), ['HEAD', 'GET'], true)) {
4848
// no-op
@@ -67,7 +67,7 @@ public function match($pathinfo)
6767
}
6868
}
6969

70-
throw new ResourceNotFoundException();
70+
throw new ResourceNotFoundException(sprintf('No routes found for "%s".', $pathinfo));
7171
}
7272

7373
private function doMatch(string $pathinfo, array &$allow = [], array &$allowSchemes = []): array
@@ -110,10 +110,8 @@ private function doMatch(string $pathinfo, array &$allow = [], array &$allowSche
110110
}
111111

112112
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
113-
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
114-
if ($hasRequiredScheme) {
115-
$allow += $requiredMethods;
116-
}
113+
if ($hasRequiredScheme && $requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
114+
$allow += $requiredMethods;
117115
continue;
118116
}
119117

@@ -162,15 +160,13 @@ private function doMatch(string $pathinfo, array &$allow = [], array &$allowSche
162160
}
163161
}
164162

165-
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
166-
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
167-
if ($hasRequiredScheme) {
168-
$allow += $requiredMethods;
169-
}
163+
if ($requiredSchemes && !isset($requiredSchemes[$context->getScheme()])) {
164+
$allowSchemes += $requiredSchemes;
170165
continue;
171166
}
172-
if (!$hasRequiredScheme) {
173-
$allowSchemes += $requiredSchemes;
167+
168+
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
169+
$allow += $requiredMethods;
174170
continue;
175171
}
176172

Matcher/UrlMatcher.php

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function match($pathinfo)
8989
return $ret;
9090
}
9191

92-
if ('/' === $pathinfo && !$this->allow) {
92+
if ('/' === $pathinfo && !$this->allow && !$this->allowSchemes) {
9393
throw new NoConfigurationException();
9494
}
9595

@@ -182,24 +182,16 @@ protected function matchCollection($pathinfo, RouteCollection $routes)
182182
if ($supportsTrailingSlash && (!$requiredMethods || \in_array('GET', $requiredMethods))) {
183183
return $this->allow = $this->allowSchemes = [];
184184
}
185-
186185
continue;
187186
}
188187

189-
$hasRequiredScheme = !$route->getSchemes() || $route->hasScheme($this->context->getScheme());
190-
if ($requiredMethods) {
191-
if (!\in_array($method, $requiredMethods)) {
192-
if ($hasRequiredScheme) {
193-
$this->allow = array_merge($this->allow, $requiredMethods);
194-
}
195-
196-
continue;
197-
}
198-
}
199-
200-
if (!$hasRequiredScheme) {
188+
if ($route->getSchemes() && !$route->hasScheme($this->context->getScheme())) {
201189
$this->allowSchemes = array_merge($this->allowSchemes, $route->getSchemes());
190+
continue;
191+
}
202192

193+
if ($requiredMethods && !\in_array($method, $requiredMethods)) {
194+
$this->allow = array_merge($this->allow, $requiredMethods);
203195
continue;
204196
}
205197

Tests/Matcher/UrlMatcherTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,7 @@ public function testNestedCollections()
747747

748748
/**
749749
* @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException
750+
* @expectedExceptionMessage No routes found for "/".
750751
*/
751752
public function testSchemeAndMethodMismatch()
752753
{

0 commit comments

Comments
 (0)