Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0693bb9

Browse filesBrowse files
ycerutonicolas-grekas
authored andcommitted
[Routing] Fixed unexpected 404 NoConfigurationException
1 parent e479b69 commit 0693bb9
Copy full SHA for 0693bb9

File tree

3 files changed

+17
-27
lines changed
Filter options

3 files changed

+17
-27
lines changed

‎src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherTrait.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherTrait.php
+10-14Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function match($pathinfo)
3939
throw new MethodNotAllowedException(array_keys($allow));
4040
}
4141
if (!$this instanceof RedirectableUrlMatcherInterface) {
42-
throw new ResourceNotFoundException();
42+
throw new ResourceNotFoundException(sprintf('No routes found for "%s".', $pathinfo));
4343
}
4444
if (!\in_array($this->context->getMethod(), ['HEAD', 'GET'], true)) {
4545
// no-op
@@ -64,7 +64,7 @@ public function match($pathinfo)
6464
}
6565
}
6666

67-
throw new ResourceNotFoundException();
67+
throw new ResourceNotFoundException(sprintf('No routes found for "%s".', $pathinfo));
6868
}
6969

7070
private function doMatch(string $pathinfo, array &$allow = [], array &$allowSchemes = []): array
@@ -107,10 +107,8 @@ private function doMatch(string $pathinfo, array &$allow = [], array &$allowSche
107107
}
108108

109109
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
110-
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
111-
if ($hasRequiredScheme) {
112-
$allow += $requiredMethods;
113-
}
110+
if ($hasRequiredScheme && $requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
111+
$allow += $requiredMethods;
114112
continue;
115113
}
116114
if (!$hasRequiredScheme) {
@@ -153,15 +151,13 @@ private function doMatch(string $pathinfo, array &$allow = [], array &$allowSche
153151
}
154152
}
155153

156-
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
157-
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
158-
if ($hasRequiredScheme) {
159-
$allow += $requiredMethods;
160-
}
161-
continue;
162-
}
163-
if (!$hasRequiredScheme) {
154+
if ($requiredSchemes && !isset($requiredSchemes[$context->getScheme()])) {
164155
$allowSchemes += $requiredSchemes;
156+
157+
continue;
158+
} elseif ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
159+
$allow += $requiredMethods;
160+
165161
continue;
166162
}
167163

‎src/Symfony/Component/Routing/Matcher/UrlMatcher.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Matcher/UrlMatcher.php
+6-13Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function match($pathinfo)
8888
return $ret;
8989
}
9090

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

@@ -185,20 +185,13 @@ protected function matchCollection($pathinfo, RouteCollection $routes)
185185
continue;
186186
}
187187

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

191+
continue;
192+
} elseif ($requiredMethods && !\in_array($method, $requiredMethods)) {
193+
$this->allow = array_merge($this->allow, $requiredMethods);
194+
202195
continue;
203196
}
204197

‎src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ public function testNestedCollections()
582582

583583
/**
584584
* @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException
585+
* @expectedExceptionMessage No routes found for "/".
585586
*/
586587
public function testSchemeAndMethodMismatch()
587588
{

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.