Merge branch '3.4' into 4.1
* 3.4: [Routing] ignore trailing slash for non-GET requests
This commit is contained in:
commit
db2c64d580
@ -564,7 +564,7 @@ EOF;
|
|||||||
}
|
}
|
||||||
}\n" : '',
|
}\n" : '',
|
||||||
$this->supportsRedirections ? "
|
$this->supportsRedirections ? "
|
||||||
if (!\$requiredMethods || isset(\$requiredMethods['GET'])) {
|
if ((!\$requiredMethods || isset(\$requiredMethods['GET'])) && 'GET' === \$canonicalMethod) {
|
||||||
return \$allow = \$allowSchemes = array();
|
return \$allow = \$allowSchemes = array();
|
||||||
}" : ''
|
}" : ''
|
||||||
);
|
);
|
||||||
@ -628,34 +628,44 @@ EOF;
|
|||||||
$matches = (bool) $compiledRoute->getPathVariables();
|
$matches = (bool) $compiledRoute->getPathVariables();
|
||||||
$hostMatches = (bool) $compiledRoute->getHostVariables();
|
$hostMatches = (bool) $compiledRoute->getHostVariables();
|
||||||
$methods = array_flip($route->getMethods());
|
$methods = array_flip($route->getMethods());
|
||||||
|
$gotoname = 'not_'.preg_replace('/[^A-Za-z0-9_]/', '', $name);
|
||||||
$code = " // $name";
|
$code = " // $name";
|
||||||
|
|
||||||
if ('/' === $route->getPath()) {
|
if ('/' === $route->getPath()) {
|
||||||
$code .= "\n";
|
$code .= "\n";
|
||||||
} elseif (!$matches) {
|
} elseif (!$matches) {
|
||||||
$code .= sprintf("
|
$code .= sprintf("
|
||||||
if ('/' !== \$pathinfo && '/' %s \$pathinfo[-1]) {
|
if ('/' !== \$pathinfo && '/' %s \$pathinfo[-1]) {%s
|
||||||
%s;
|
goto $gotoname;
|
||||||
}\n\n",
|
}\n\n",
|
||||||
$hasTrailingSlash ? '!==' : '===',
|
$hasTrailingSlash ? '!==' : '===',
|
||||||
$this->supportsRedirections && (!$methods || isset($methods['GET'])) ? 'return $allow = $allowSchemes = array()' : 'break'
|
$this->supportsRedirections && (!$methods || isset($methods['GET'])) ? "
|
||||||
|
if ('GET' === \$canonicalMethod) {
|
||||||
|
return \$allow = \$allowSchemes = array();
|
||||||
|
}" : ''
|
||||||
);
|
);
|
||||||
} elseif ($hasTrailingSlash) {
|
} elseif ($hasTrailingSlash) {
|
||||||
$code .= sprintf("
|
$code .= sprintf("
|
||||||
if ('/' !== \$pathinfo[-1]) {
|
if ('/' !== \$pathinfo[-1]) {%s
|
||||||
%s;
|
goto $gotoname;
|
||||||
}
|
}
|
||||||
if ('/' !== \$pathinfo && preg_match(\$regex, substr(\$pathinfo, 0, -1), \$n) && \$m === (int) \$n['MARK']) {
|
if ('/' !== \$pathinfo && preg_match(\$regex, substr(\$pathinfo, 0, -1), \$n) && \$m === (int) \$n['MARK']) {
|
||||||
\$matches = \$n;
|
\$matches = \$n;
|
||||||
}\n\n",
|
}\n\n",
|
||||||
$this->supportsRedirections && (!$methods || isset($methods['GET'])) ? 'return $allow = $allowSchemes = array()' : 'break'
|
$this->supportsRedirections && (!$methods || isset($methods['GET'])) ? "
|
||||||
|
if ('GET' === \$canonicalMethod) {
|
||||||
|
return \$allow = \$allowSchemes = array();
|
||||||
|
}" : ''
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$code .= sprintf("
|
$code .= sprintf("
|
||||||
if ('/' !== \$pathinfo && '/' === \$pathinfo[-1] && preg_match(\$regex, substr(\$pathinfo, 0, -1), \$n) && \$m === (int) \$n['MARK']) {
|
if ('/' !== \$pathinfo && '/' === \$pathinfo[-1] && preg_match(\$regex, substr(\$pathinfo, 0, -1), \$n) && \$m === (int) \$n['MARK']) {%s
|
||||||
%s;
|
goto $gotoname;
|
||||||
}\n\n",
|
}\n\n",
|
||||||
$this->supportsRedirections && (!$methods || isset($methods['GET'])) ? 'return $allow = $allowSchemes = array()' : 'break'
|
$this->supportsRedirections && (!$methods || isset($methods['GET'])) ? "
|
||||||
|
if ('GET' === \$canonicalMethod) {
|
||||||
|
return \$allow = \$allowSchemes = array();
|
||||||
|
}" : ''
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -687,8 +697,6 @@ EOF;
|
|||||||
$code = $this->indent($code);
|
$code = $this->indent($code);
|
||||||
}
|
}
|
||||||
|
|
||||||
$gotoname = 'not_'.preg_replace('/[^A-Za-z0-9_]/', '', $name);
|
|
||||||
|
|
||||||
// the offset where the return value is appended below, with indendation
|
// the offset where the return value is appended below, with indendation
|
||||||
$retOffset = 12 + \strlen($code);
|
$retOffset = 12 + \strlen($code);
|
||||||
$defaults = $route->getDefaults();
|
$defaults = $route->getDefaults();
|
||||||
@ -770,16 +778,10 @@ EOF;
|
|||||||
$code = substr_replace($code, 'return', $retOffset, 6);
|
$code = substr_replace($code, 'return', $retOffset, 6);
|
||||||
}
|
}
|
||||||
if ($conditions) {
|
if ($conditions) {
|
||||||
$code .= " }\n";
|
$code = $this->indent($code)." }\n";
|
||||||
} elseif ($schemes || $methods) {
|
|
||||||
$code .= ' ';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($schemes || $methods) {
|
return $code." $gotoname:\n";
|
||||||
$code .= " $gotoname:\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
return $conditions ? $this->indent($code) : $code;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getExpressionLanguage()
|
private function getExpressionLanguage()
|
||||||
|
@ -130,6 +130,10 @@ class UrlMatcher implements UrlMatcherInterface, RequestMatcherInterface
|
|||||||
*/
|
*/
|
||||||
protected function matchCollection($pathinfo, RouteCollection $routes)
|
protected function matchCollection($pathinfo, RouteCollection $routes)
|
||||||
{
|
{
|
||||||
|
// HEAD and GET are equivalent as per RFC
|
||||||
|
if ('HEAD' === $method = $this->context->getMethod()) {
|
||||||
|
$method = 'GET';
|
||||||
|
}
|
||||||
$supportsTrailingSlash = '/' !== $pathinfo && '' !== $pathinfo && $this instanceof RedirectableUrlMatcherInterface;
|
$supportsTrailingSlash = '/' !== $pathinfo && '' !== $pathinfo && $this instanceof RedirectableUrlMatcherInterface;
|
||||||
|
|
||||||
foreach ($routes as $name => $route) {
|
foreach ($routes as $name => $route) {
|
||||||
@ -140,7 +144,7 @@ class UrlMatcher implements UrlMatcherInterface, RequestMatcherInterface
|
|||||||
// check the static prefix of the URL first. Only use the more expensive preg_match when it matches
|
// check the static prefix of the URL first. Only use the more expensive preg_match when it matches
|
||||||
if ('' === $staticPrefix || 0 === strpos($pathinfo, $staticPrefix)) {
|
if ('' === $staticPrefix || 0 === strpos($pathinfo, $staticPrefix)) {
|
||||||
// no-op
|
// no-op
|
||||||
} elseif (!$supportsTrailingSlash || ($requiredMethods && !\in_array('GET', $requiredMethods))) {
|
} elseif (!$supportsTrailingSlash || ($requiredMethods && !\in_array('GET', $requiredMethods)) || 'GET' !== $method) {
|
||||||
continue;
|
continue;
|
||||||
} elseif ('/' === $staticPrefix[-1] && substr($staticPrefix, 0, -1) === $pathinfo) {
|
} elseif ('/' === $staticPrefix[-1] && substr($staticPrefix, 0, -1) === $pathinfo) {
|
||||||
return $this->allow = $this->allowSchemes = array();
|
return $this->allow = $this->allowSchemes = array();
|
||||||
@ -170,7 +174,7 @@ class UrlMatcher implements UrlMatcherInterface, RequestMatcherInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
|
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
|
||||||
if (!$requiredMethods || \in_array('GET', $requiredMethods)) {
|
if ((!$requiredMethods || \in_array('GET', $requiredMethods)) && 'GET' === $method) {
|
||||||
return $this->allow = $this->allowSchemes = array();
|
return $this->allow = $this->allowSchemes = array();
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
@ -190,11 +194,6 @@ class UrlMatcher implements UrlMatcherInterface, RequestMatcherInterface
|
|||||||
|
|
||||||
$hasRequiredScheme = !$route->getSchemes() || $route->hasScheme($this->context->getScheme());
|
$hasRequiredScheme = !$route->getSchemes() || $route->hasScheme($this->context->getScheme());
|
||||||
if ($requiredMethods) {
|
if ($requiredMethods) {
|
||||||
// HEAD and GET are equivalent as per RFC
|
|
||||||
if ('HEAD' === $method = $this->context->getMethod()) {
|
|
||||||
$method = 'GET';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!\in_array($method, $requiredMethods)) {
|
if (!\in_array($method, $requiredMethods)) {
|
||||||
if ($hasRequiredScheme) {
|
if ($hasRequiredScheme) {
|
||||||
$this->allow = array_merge($this->allow, $requiredMethods);
|
$this->allow = array_merge($this->allow, $requiredMethods);
|
||||||
|
@ -143,17 +143,18 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
|
|||||||
|
|
||||||
// baz4
|
// baz4
|
||||||
if ('/' !== $pathinfo[-1]) {
|
if ('/' !== $pathinfo[-1]) {
|
||||||
break;
|
goto not_baz4;
|
||||||
}
|
}
|
||||||
if ('/' !== $pathinfo && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
if ('/' !== $pathinfo && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
||||||
$matches = $n;
|
$matches = $n;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->mergeDefaults(array('_route' => 'baz4') + $matches, array());
|
return $this->mergeDefaults(array('_route' => 'baz4') + $matches, array());
|
||||||
|
not_baz4:
|
||||||
|
|
||||||
// baz5
|
// baz5
|
||||||
if ('/' !== $pathinfo[-1]) {
|
if ('/' !== $pathinfo[-1]) {
|
||||||
break;
|
goto not_baz5;
|
||||||
}
|
}
|
||||||
if ('/' !== $pathinfo && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
if ('/' !== $pathinfo && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
||||||
$matches = $n;
|
$matches = $n;
|
||||||
@ -170,7 +171,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
|
|||||||
|
|
||||||
// baz.baz6
|
// baz.baz6
|
||||||
if ('/' !== $pathinfo[-1]) {
|
if ('/' !== $pathinfo[-1]) {
|
||||||
break;
|
goto not_bazbaz6;
|
||||||
}
|
}
|
||||||
if ('/' !== $pathinfo && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
if ('/' !== $pathinfo && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
||||||
$matches = $n;
|
$matches = $n;
|
||||||
@ -191,7 +192,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
|
|||||||
|
|
||||||
// foo1
|
// foo1
|
||||||
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
||||||
break;
|
goto not_foo1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$ret = $this->mergeDefaults(array('_route' => 'foo1') + $matches, array());
|
$ret = $this->mergeDefaults(array('_route' => 'foo1') + $matches, array());
|
||||||
@ -209,10 +210,11 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
|
|||||||
|
|
||||||
// foo2
|
// foo2
|
||||||
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
||||||
break;
|
goto not_foo2;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->mergeDefaults(array('_route' => 'foo2') + $matches, array());
|
return $this->mergeDefaults(array('_route' => 'foo2') + $matches, array());
|
||||||
|
not_foo2:
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 279:
|
case 279:
|
||||||
@ -220,10 +222,11 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
|
|||||||
|
|
||||||
// foo3
|
// foo3
|
||||||
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
||||||
break;
|
goto not_foo3;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->mergeDefaults(array('_route' => 'foo3') + $matches, array());
|
return $this->mergeDefaults(array('_route' => 'foo3') + $matches, array());
|
||||||
|
not_foo3:
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -128,7 +128,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
|
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
|
||||||
if (!$requiredMethods || isset($requiredMethods['GET'])) {
|
if ((!$requiredMethods || isset($requiredMethods['GET'])) && 'GET' === $canonicalMethod) {
|
||||||
return $allow = $allowSchemes = array();
|
return $allow = $allowSchemes = array();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -46,17 +46,19 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
|
|||||||
|
|
||||||
// r1
|
// r1
|
||||||
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
||||||
break;
|
goto not_r1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->mergeDefaults(array('_route' => 'r1') + $matches, array());
|
return $this->mergeDefaults(array('_route' => 'r1') + $matches, array());
|
||||||
|
not_r1:
|
||||||
|
|
||||||
// r2
|
// r2
|
||||||
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
||||||
break;
|
goto not_r2;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->mergeDefaults(array('_route' => 'r2') + $matches, array());
|
return $this->mergeDefaults(array('_route' => 'r2') + $matches, array());
|
||||||
|
not_r2:
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
|||||||
|
|
||||||
if ('/' !== $pathinfo) {
|
if ('/' !== $pathinfo) {
|
||||||
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
|
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
|
||||||
if (!$requiredMethods || isset($requiredMethods['GET'])) {
|
if ((!$requiredMethods || isset($requiredMethods['GET'])) && 'GET' === $canonicalMethod) {
|
||||||
return $allow = $allowSchemes = array();
|
return $allow = $allowSchemes = array();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -183,17 +183,21 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
|||||||
|
|
||||||
// baz4
|
// baz4
|
||||||
if ('/' !== $pathinfo[-1]) {
|
if ('/' !== $pathinfo[-1]) {
|
||||||
return $allow = $allowSchemes = array();
|
if ('GET' === $canonicalMethod) {
|
||||||
|
return $allow = $allowSchemes = array();
|
||||||
|
}
|
||||||
|
goto not_baz4;
|
||||||
}
|
}
|
||||||
if ('/' !== $pathinfo && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
if ('/' !== $pathinfo && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
||||||
$matches = $n;
|
$matches = $n;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->mergeDefaults(array('_route' => 'baz4') + $matches, array());
|
return $this->mergeDefaults(array('_route' => 'baz4') + $matches, array());
|
||||||
|
not_baz4:
|
||||||
|
|
||||||
// baz5
|
// baz5
|
||||||
if ('/' !== $pathinfo[-1]) {
|
if ('/' !== $pathinfo[-1]) {
|
||||||
break;
|
goto not_baz5;
|
||||||
}
|
}
|
||||||
if ('/' !== $pathinfo && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
if ('/' !== $pathinfo && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
||||||
$matches = $n;
|
$matches = $n;
|
||||||
@ -210,7 +214,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
|||||||
|
|
||||||
// baz.baz6
|
// baz.baz6
|
||||||
if ('/' !== $pathinfo[-1]) {
|
if ('/' !== $pathinfo[-1]) {
|
||||||
break;
|
goto not_bazbaz6;
|
||||||
}
|
}
|
||||||
if ('/' !== $pathinfo && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
if ('/' !== $pathinfo && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
||||||
$matches = $n;
|
$matches = $n;
|
||||||
@ -231,7 +235,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
|||||||
|
|
||||||
// foo1
|
// foo1
|
||||||
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
||||||
break;
|
goto not_foo1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$ret = $this->mergeDefaults(array('_route' => 'foo1') + $matches, array());
|
$ret = $this->mergeDefaults(array('_route' => 'foo1') + $matches, array());
|
||||||
@ -249,10 +253,14 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
|||||||
|
|
||||||
// foo2
|
// foo2
|
||||||
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
||||||
return $allow = $allowSchemes = array();
|
if ('GET' === $canonicalMethod) {
|
||||||
|
return $allow = $allowSchemes = array();
|
||||||
|
}
|
||||||
|
goto not_foo2;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->mergeDefaults(array('_route' => 'foo2') + $matches, array());
|
return $this->mergeDefaults(array('_route' => 'foo2') + $matches, array());
|
||||||
|
not_foo2:
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 279:
|
case 279:
|
||||||
@ -260,10 +268,14 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
|||||||
|
|
||||||
// foo3
|
// foo3
|
||||||
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
||||||
return $allow = $allowSchemes = array();
|
if ('GET' === $canonicalMethod) {
|
||||||
|
return $allow = $allowSchemes = array();
|
||||||
|
}
|
||||||
|
goto not_foo3;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->mergeDefaults(array('_route' => 'foo3') + $matches, array());
|
return $this->mergeDefaults(array('_route' => 'foo3') + $matches, array());
|
||||||
|
not_foo3:
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -299,7 +311,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
|
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
|
||||||
if (!$requiredMethods || isset($requiredMethods['GET'])) {
|
if ((!$requiredMethods || isset($requiredMethods['GET'])) && 'GET' === $canonicalMethod) {
|
||||||
return $allow = $allowSchemes = array();
|
return $allow = $allowSchemes = array();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -30,12 +30,13 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
|
|||||||
case '/with-condition':
|
case '/with-condition':
|
||||||
// with-condition
|
// with-condition
|
||||||
if ('/' !== $pathinfo && '/' === $pathinfo[-1]) {
|
if ('/' !== $pathinfo && '/' === $pathinfo[-1]) {
|
||||||
break;
|
goto not_withcondition;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($context->getMethod() == "GET")) {
|
if (($context->getMethod() == "GET")) {
|
||||||
return array('_route' => 'with-condition');
|
return array('_route' => 'with-condition');
|
||||||
}
|
}
|
||||||
|
not_withcondition:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$routes = array(
|
$routes = array(
|
||||||
|
@ -30,7 +30,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
|
|||||||
case '/put_and_post':
|
case '/put_and_post':
|
||||||
// put_and_post
|
// put_and_post
|
||||||
if ('/' !== $pathinfo && '/' === $pathinfo[-1]) {
|
if ('/' !== $pathinfo && '/' === $pathinfo[-1]) {
|
||||||
break;
|
goto not_put_and_post;
|
||||||
}
|
}
|
||||||
|
|
||||||
$ret = array('_route' => 'put_and_post');
|
$ret = array('_route' => 'put_and_post');
|
||||||
@ -43,7 +43,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
|
|||||||
not_put_and_post:
|
not_put_and_post:
|
||||||
// put_and_get_and_head
|
// put_and_get_and_head
|
||||||
if ('/' !== $pathinfo && '/' === $pathinfo[-1]) {
|
if ('/' !== $pathinfo && '/' === $pathinfo[-1]) {
|
||||||
break;
|
goto not_put_and_get_and_head;
|
||||||
}
|
}
|
||||||
|
|
||||||
$ret = array('_route' => 'put_and_get_and_head');
|
$ret = array('_route' => 'put_and_get_and_head');
|
||||||
|
@ -85,7 +85,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
|||||||
|
|
||||||
if ('/' !== $pathinfo) {
|
if ('/' !== $pathinfo) {
|
||||||
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
|
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
|
||||||
if (!$requiredMethods || isset($requiredMethods['GET'])) {
|
if ((!$requiredMethods || isset($requiredMethods['GET'])) && 'GET' === $canonicalMethod) {
|
||||||
return $allow = $allowSchemes = array();
|
return $allow = $allowSchemes = array();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -136,7 +136,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
|
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
|
||||||
if (!$requiredMethods || isset($requiredMethods['GET'])) {
|
if ((!$requiredMethods || isset($requiredMethods['GET'])) && 'GET' === $canonicalMethod) {
|
||||||
return $allow = $allowSchemes = array();
|
return $allow = $allowSchemes = array();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -81,7 +81,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
|||||||
|
|
||||||
if ('/' !== $pathinfo) {
|
if ('/' !== $pathinfo) {
|
||||||
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
|
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
|
||||||
if (!$requiredMethods || isset($requiredMethods['GET'])) {
|
if ((!$requiredMethods || isset($requiredMethods['GET'])) && 'GET' === $canonicalMethod) {
|
||||||
return $allow = $allowSchemes = array();
|
return $allow = $allowSchemes = array();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -148,7 +148,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
|
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
|
||||||
if (!$requiredMethods || isset($requiredMethods['GET'])) {
|
if ((!$requiredMethods || isset($requiredMethods['GET'])) && 'GET' === $canonicalMethod) {
|
||||||
return $allow = $allowSchemes = array();
|
return $allow = $allowSchemes = array();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -33,14 +33,17 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
|
|||||||
if (preg_match('#^(?P<d>[^\\.]++)\\.e\\.c\\.b\\.a$#sDi', $host, $hostMatches)) {
|
if (preg_match('#^(?P<d>[^\\.]++)\\.e\\.c\\.b\\.a$#sDi', $host, $hostMatches)) {
|
||||||
return $this->mergeDefaults(array('_route' => 'a') + $hostMatches, array());
|
return $this->mergeDefaults(array('_route' => 'a') + $hostMatches, array());
|
||||||
}
|
}
|
||||||
|
not_a:
|
||||||
// c
|
// c
|
||||||
if (preg_match('#^(?P<e>[^\\.]++)\\.e\\.c\\.b\\.a$#sDi', $host, $hostMatches)) {
|
if (preg_match('#^(?P<e>[^\\.]++)\\.e\\.c\\.b\\.a$#sDi', $host, $hostMatches)) {
|
||||||
return $this->mergeDefaults(array('_route' => 'c') + $hostMatches, array());
|
return $this->mergeDefaults(array('_route' => 'c') + $hostMatches, array());
|
||||||
}
|
}
|
||||||
|
not_c:
|
||||||
// b
|
// b
|
||||||
if ('d.c.b.a' === $host) {
|
if ('d.c.b.a' === $host) {
|
||||||
return array('_route' => 'b');
|
return array('_route' => 'b');
|
||||||
}
|
}
|
||||||
|
not_b:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -720,6 +720,17 @@ class UrlMatcherTest extends TestCase
|
|||||||
'customerId' => '123',
|
'customerId' => '123',
|
||||||
);
|
);
|
||||||
$this->assertEquals($expected, $matcher->match('/api/customers/123/contactpersons'));
|
$this->assertEquals($expected, $matcher->match('/api/customers/123/contactpersons'));
|
||||||
|
|
||||||
|
$coll = new RouteCollection();
|
||||||
|
$coll->add('a', new Route('/api/customers/{customerId}/contactpersons/', array(), array(), array(), '', array(), array('get')));
|
||||||
|
$coll->add('b', new Route('/api/customers/{customerId}/contactpersons', array(), array(), array(), '', array(), array('post')));
|
||||||
|
|
||||||
|
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'POST'));
|
||||||
|
$expected = array(
|
||||||
|
'_route' => 'b',
|
||||||
|
'customerId' => '123',
|
||||||
|
);
|
||||||
|
$this->assertEquals($expected, $matcher->match('/api/customers/123/contactpersons'));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getUrlMatcher(RouteCollection $routes, RequestContext $context = null)
|
protected function getUrlMatcher(RouteCollection $routes, RequestContext $context = null)
|
||||||
|
Reference in New Issue
Block a user