Merge branch '3.4' into 4.0

* 3.4:
  fix merge
This commit is contained in:
Nicolas Grekas 2018-02-26 18:39:40 +01:00
commit 05782adc3b
6 changed files with 80 additions and 118 deletions

View File

@ -318,17 +318,21 @@ EOF;
EOF;
}
if ($methods) {
$methodVariable = in_array('GET', $methods) ? '$canonicalMethod' : '$requestMethod';
$methods = implode("', '", $methods);
}
if ($schemes = $route->getSchemes()) {
if (!$supportsRedirections) {
throw new \LogicException('The "schemes" requirement is only supported for URL matchers that implement RedirectableUrlMatcherInterface.');
}
$schemes = str_replace("\n", '', var_export(array_flip($schemes), true));
if ($methods) {
$methods = implode("', '", $methods);
$code .= <<<EOF
\$requiredSchemes = $schemes;
\$hasRequiredScheme = isset(\$requiredSchemes[\$context->getScheme()]);
if (!in_array(\$context->getMethod(), array('$methods'))) {
if (!in_array($methodVariable, array('$methods'))) {
if (\$hasRequiredScheme) {
\$allow = array_merge(\$allow, array('$methods'));
}
@ -359,56 +363,14 @@ EOF;
EOF;
}
} elseif ($methods) {
if (1 === count($methods)) {
if ('HEAD' === $methods[0]) {
$code .= <<<EOF
if ('HEAD' !== \$requestMethod) {
\$allow[] = 'HEAD';
goto $gotoname;
}
EOF;
} else {
$code .= <<<EOF
if ('$methods[0]' !== \$canonicalMethod) {
\$allow[] = '$methods[0]';
goto $gotoname;
}
EOF;
}
} else {
$methodVariable = 'requestMethod';
if (in_array('GET', $methods)) {
// Since we treat HEAD requests like GET requests we don't need to match it.
$methodVariable = 'canonicalMethod';
$methods = array_values(array_filter($methods, function ($method) { return 'HEAD' !== $method; }));
}
if (1 === count($methods)) {
$code .= <<<EOF
if ('$methods[0]' !== \$$methodVariable) {
\$allow[] = '$methods[0]';
goto $gotoname;
}
EOF;
} else {
$methods = implode("', '", $methods);
$code .= <<<EOF
if (!in_array(\$$methodVariable, array('$methods'))) {
$code .= <<<EOF
if (!in_array($methodVariable, array('$methods'))) {
\$allow = array_merge(\$allow, array('$methods'));
goto $gotoname;
}
EOF;
}
}
}
if ($hasTrailingSlash || $schemes || $methods) {

View File

@ -45,8 +45,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
// bar
if (preg_match('#^/bar/(?P<foo>[^/]++)$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'bar')), array ());
if ('GET' !== $canonicalMethod) {
$allow[] = 'GET';
if (!in_array($canonicalMethod, array('GET', 'HEAD'))) {
$allow = array_merge($allow, array('GET', 'HEAD'));
goto not_bar;
}
@ -57,8 +57,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
// barhead
if (0 === strpos($pathinfo, '/barhead') && preg_match('#^/barhead/(?P<foo>[^/]++)$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'barhead')), array ());
if ('GET' !== $canonicalMethod) {
$allow[] = 'GET';
if (!in_array($canonicalMethod, array('GET'))) {
$allow = array_merge($allow, array('GET'));
goto not_barhead;
}
@ -95,8 +95,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
// baz5
if (preg_match('#^/test/(?P<foo>[^/]++)/$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'baz5')), array ());
if ('POST' !== $canonicalMethod) {
$allow[] = 'POST';
if (!in_array($requestMethod, array('POST'))) {
$allow = array_merge($allow, array('POST'));
goto not_baz5;
}
@ -107,8 +107,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
// baz.baz6
if (preg_match('#^/test/(?P<foo>[^/]++)/$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'baz.baz6')), array ());
if ('PUT' !== $canonicalMethod) {
$allow[] = 'PUT';
if (!in_array($requestMethod, array('PUT'))) {
$allow = array_merge($allow, array('PUT'));
goto not_bazbaz6;
}

View File

@ -45,8 +45,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
// bar
if (preg_match('#^/bar/(?P<foo>[^/]++)$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'bar')), array ());
if ('GET' !== $canonicalMethod) {
$allow[] = 'GET';
if (!in_array($canonicalMethod, array('GET', 'HEAD'))) {
$allow = array_merge($allow, array('GET', 'HEAD'));
goto not_bar;
}
@ -57,8 +57,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
// barhead
if (0 === strpos($pathinfo, '/barhead') && preg_match('#^/barhead/(?P<foo>[^/]++)$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'barhead')), array ());
if ('GET' !== $canonicalMethod) {
$allow[] = 'GET';
if (!in_array($canonicalMethod, array('GET'))) {
$allow = array_merge($allow, array('GET'));
goto not_barhead;
}
@ -115,8 +115,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
// baz5
if (preg_match('#^/test/(?P<foo>[^/]++)/$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'baz5')), array ());
if ('POST' !== $canonicalMethod) {
$allow[] = 'POST';
if (!in_array($requestMethod, array('POST'))) {
$allow = array_merge($allow, array('POST'));
goto not_baz5;
}
@ -127,8 +127,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
// baz.baz6
if (preg_match('#^/test/(?P<foo>[^/]++)/$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'baz.baz6')), array ());
if ('PUT' !== $canonicalMethod) {
$allow[] = 'PUT';
if (!in_array($requestMethod, array('PUT'))) {
$allow = array_merge($allow, array('PUT'));
goto not_bazbaz6;
}

View File

@ -31,8 +31,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
// just_head
if ('/just_head' === $pathinfo) {
$ret = array('_route' => 'just_head');
if ('HEAD' !== $requestMethod) {
$allow[] = 'HEAD';
if (!in_array($requestMethod, array('HEAD'))) {
$allow = array_merge($allow, array('HEAD'));
goto not_just_head;
}
@ -43,8 +43,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
// head_and_get
if ('/head_and_get' === $pathinfo) {
$ret = array('_route' => 'head_and_get');
if ('GET' !== $canonicalMethod) {
$allow[] = 'GET';
if (!in_array($canonicalMethod, array('HEAD', 'GET'))) {
$allow = array_merge($allow, array('HEAD', 'GET'));
goto not_head_and_get;
}
@ -55,8 +55,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
// get_and_head
if ('/get_and_head' === $pathinfo) {
$ret = array('_route' => 'get_and_head');
if ('GET' !== $canonicalMethod) {
$allow[] = 'GET';
if (!in_array($canonicalMethod, array('GET', 'HEAD'))) {
$allow = array_merge($allow, array('GET', 'HEAD'));
goto not_get_and_head;
}
@ -92,8 +92,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
// put_and_get_and_head
if ('/put_and_post' === $pathinfo) {
$ret = array('_route' => 'put_and_get_and_head');
if (!in_array($canonicalMethod, array('PUT', 'GET'))) {
$allow = array_merge($allow, array('PUT', 'GET'));
if (!in_array($canonicalMethod, array('PUT', 'GET', 'HEAD'))) {
$allow = array_merge($allow, array('PUT', 'GET', 'HEAD'));
goto not_put_and_get_and_head;
}

View File

@ -37,8 +37,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
// simple_trailing_slash_GET_method
if ('/trailing/simple/get-method/' === $pathinfo) {
$ret = array('_route' => 'simple_trailing_slash_GET_method');
if ('GET' !== $canonicalMethod) {
$allow[] = 'GET';
if (!in_array($canonicalMethod, array('GET'))) {
$allow = array_merge($allow, array('GET'));
goto not_simple_trailing_slash_GET_method;
}
@ -49,8 +49,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
// simple_trailing_slash_HEAD_method
if ('/trailing/simple/head-method/' === $pathinfo) {
$ret = array('_route' => 'simple_trailing_slash_HEAD_method');
if ('HEAD' !== $requestMethod) {
$allow[] = 'HEAD';
if (!in_array($requestMethod, array('HEAD'))) {
$allow = array_merge($allow, array('HEAD'));
goto not_simple_trailing_slash_HEAD_method;
}
@ -61,8 +61,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
// simple_trailing_slash_POST_method
if ('/trailing/simple/post-method/' === $pathinfo) {
$ret = array('_route' => 'simple_trailing_slash_POST_method');
if ('POST' !== $canonicalMethod) {
$allow[] = 'POST';
if (!in_array($requestMethod, array('POST'))) {
$allow = array_merge($allow, array('POST'));
goto not_simple_trailing_slash_POST_method;
}
@ -81,8 +81,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
// regex_trailing_slash_GET_method
if (0 === strpos($pathinfo, '/trailing/regex/get-method') && preg_match('#^/trailing/regex/get\\-method/(?P<param>[^/]++)/$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_GET_method')), array ());
if ('GET' !== $canonicalMethod) {
$allow[] = 'GET';
if (!in_array($canonicalMethod, array('GET'))) {
$allow = array_merge($allow, array('GET'));
goto not_regex_trailing_slash_GET_method;
}
@ -93,8 +93,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
// regex_trailing_slash_HEAD_method
if (0 === strpos($pathinfo, '/trailing/regex/head-method') && preg_match('#^/trailing/regex/head\\-method/(?P<param>[^/]++)/$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_HEAD_method')), array ());
if ('HEAD' !== $requestMethod) {
$allow[] = 'HEAD';
if (!in_array($requestMethod, array('HEAD'))) {
$allow = array_merge($allow, array('HEAD'));
goto not_regex_trailing_slash_HEAD_method;
}
@ -105,8 +105,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
// regex_trailing_slash_POST_method
if (0 === strpos($pathinfo, '/trailing/regex/post-method') && preg_match('#^/trailing/regex/post\\-method/(?P<param>[^/]++)/$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_POST_method')), array ());
if ('POST' !== $canonicalMethod) {
$allow[] = 'POST';
if (!in_array($requestMethod, array('POST'))) {
$allow = array_merge($allow, array('POST'));
goto not_regex_trailing_slash_POST_method;
}
@ -125,8 +125,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
// simple_not_trailing_slash_GET_method
if ('/not-trailing/simple/get-method' === $pathinfo) {
$ret = array('_route' => 'simple_not_trailing_slash_GET_method');
if ('GET' !== $canonicalMethod) {
$allow[] = 'GET';
if (!in_array($canonicalMethod, array('GET'))) {
$allow = array_merge($allow, array('GET'));
goto not_simple_not_trailing_slash_GET_method;
}
@ -137,8 +137,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
// simple_not_trailing_slash_HEAD_method
if ('/not-trailing/simple/head-method' === $pathinfo) {
$ret = array('_route' => 'simple_not_trailing_slash_HEAD_method');
if ('HEAD' !== $requestMethod) {
$allow[] = 'HEAD';
if (!in_array($requestMethod, array('HEAD'))) {
$allow = array_merge($allow, array('HEAD'));
goto not_simple_not_trailing_slash_HEAD_method;
}
@ -149,8 +149,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
// simple_not_trailing_slash_POST_method
if ('/not-trailing/simple/post-method' === $pathinfo) {
$ret = array('_route' => 'simple_not_trailing_slash_POST_method');
if ('POST' !== $canonicalMethod) {
$allow[] = 'POST';
if (!in_array($requestMethod, array('POST'))) {
$allow = array_merge($allow, array('POST'));
goto not_simple_not_trailing_slash_POST_method;
}
@ -169,8 +169,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
// regex_not_trailing_slash_GET_method
if (0 === strpos($pathinfo, '/not-trailing/regex/get-method') && preg_match('#^/not\\-trailing/regex/get\\-method/(?P<param>[^/]++)$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_not_trailing_slash_GET_method')), array ());
if ('GET' !== $canonicalMethod) {
$allow[] = 'GET';
if (!in_array($canonicalMethod, array('GET'))) {
$allow = array_merge($allow, array('GET'));
goto not_regex_not_trailing_slash_GET_method;
}
@ -181,8 +181,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
// regex_not_trailing_slash_HEAD_method
if (0 === strpos($pathinfo, '/not-trailing/regex/head-method') && preg_match('#^/not\\-trailing/regex/head\\-method/(?P<param>[^/]++)$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_not_trailing_slash_HEAD_method')), array ());
if ('HEAD' !== $requestMethod) {
$allow[] = 'HEAD';
if (!in_array($requestMethod, array('HEAD'))) {
$allow = array_merge($allow, array('HEAD'));
goto not_regex_not_trailing_slash_HEAD_method;
}
@ -193,8 +193,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
// regex_not_trailing_slash_POST_method
if (0 === strpos($pathinfo, '/not-trailing/regex/post-method') && preg_match('#^/not\\-trailing/regex/post\\-method/(?P<param>[^/]++)$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_not_trailing_slash_POST_method')), array ());
if ('POST' !== $canonicalMethod) {
$allow[] = 'POST';
if (!in_array($requestMethod, array('POST'))) {
$allow = array_merge($allow, array('POST'));
goto not_regex_not_trailing_slash_POST_method;
}

View File

@ -55,8 +55,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'simple_trailing_slash_GET_method'));
}
if ('GET' !== $canonicalMethod) {
$allow[] = 'GET';
if (!in_array($canonicalMethod, array('GET'))) {
$allow = array_merge($allow, array('GET'));
goto not_simple_trailing_slash_GET_method;
}
@ -67,8 +67,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
// simple_trailing_slash_HEAD_method
if ('/trailing/simple/head-method/' === $pathinfo) {
$ret = array('_route' => 'simple_trailing_slash_HEAD_method');
if ('HEAD' !== $requestMethod) {
$allow[] = 'HEAD';
if (!in_array($requestMethod, array('HEAD'))) {
$allow = array_merge($allow, array('HEAD'));
goto not_simple_trailing_slash_HEAD_method;
}
@ -79,8 +79,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
// simple_trailing_slash_POST_method
if ('/trailing/simple/post-method/' === $pathinfo) {
$ret = array('_route' => 'simple_trailing_slash_POST_method');
if ('POST' !== $canonicalMethod) {
$allow[] = 'POST';
if (!in_array($requestMethod, array('POST'))) {
$allow = array_merge($allow, array('POST'));
goto not_simple_trailing_slash_POST_method;
}
@ -117,8 +117,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'regex_trailing_slash_GET_method'));
}
if ('GET' !== $canonicalMethod) {
$allow[] = 'GET';
if (!in_array($canonicalMethod, array('GET'))) {
$allow = array_merge($allow, array('GET'));
goto not_regex_trailing_slash_GET_method;
}
@ -129,8 +129,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
// regex_trailing_slash_HEAD_method
if (0 === strpos($pathinfo, '/trailing/regex/head-method') && preg_match('#^/trailing/regex/head\\-method/(?P<param>[^/]++)/$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_HEAD_method')), array ());
if ('HEAD' !== $requestMethod) {
$allow[] = 'HEAD';
if (!in_array($requestMethod, array('HEAD'))) {
$allow = array_merge($allow, array('HEAD'));
goto not_regex_trailing_slash_HEAD_method;
}
@ -141,8 +141,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
// regex_trailing_slash_POST_method
if (0 === strpos($pathinfo, '/trailing/regex/post-method') && preg_match('#^/trailing/regex/post\\-method/(?P<param>[^/]++)/$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_POST_method')), array ());
if ('POST' !== $canonicalMethod) {
$allow[] = 'POST';
if (!in_array($requestMethod, array('POST'))) {
$allow = array_merge($allow, array('POST'));
goto not_regex_trailing_slash_POST_method;
}
@ -161,8 +161,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
// simple_not_trailing_slash_GET_method
if ('/not-trailing/simple/get-method' === $pathinfo) {
$ret = array('_route' => 'simple_not_trailing_slash_GET_method');
if ('GET' !== $canonicalMethod) {
$allow[] = 'GET';
if (!in_array($canonicalMethod, array('GET'))) {
$allow = array_merge($allow, array('GET'));
goto not_simple_not_trailing_slash_GET_method;
}
@ -173,8 +173,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
// simple_not_trailing_slash_HEAD_method
if ('/not-trailing/simple/head-method' === $pathinfo) {
$ret = array('_route' => 'simple_not_trailing_slash_HEAD_method');
if ('HEAD' !== $requestMethod) {
$allow[] = 'HEAD';
if (!in_array($requestMethod, array('HEAD'))) {
$allow = array_merge($allow, array('HEAD'));
goto not_simple_not_trailing_slash_HEAD_method;
}
@ -185,8 +185,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
// simple_not_trailing_slash_POST_method
if ('/not-trailing/simple/post-method' === $pathinfo) {
$ret = array('_route' => 'simple_not_trailing_slash_POST_method');
if ('POST' !== $canonicalMethod) {
$allow[] = 'POST';
if (!in_array($requestMethod, array('POST'))) {
$allow = array_merge($allow, array('POST'));
goto not_simple_not_trailing_slash_POST_method;
}
@ -205,8 +205,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
// regex_not_trailing_slash_GET_method
if (0 === strpos($pathinfo, '/not-trailing/regex/get-method') && preg_match('#^/not\\-trailing/regex/get\\-method/(?P<param>[^/]++)$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_not_trailing_slash_GET_method')), array ());
if ('GET' !== $canonicalMethod) {
$allow[] = 'GET';
if (!in_array($canonicalMethod, array('GET'))) {
$allow = array_merge($allow, array('GET'));
goto not_regex_not_trailing_slash_GET_method;
}
@ -217,8 +217,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
// regex_not_trailing_slash_HEAD_method
if (0 === strpos($pathinfo, '/not-trailing/regex/head-method') && preg_match('#^/not\\-trailing/regex/head\\-method/(?P<param>[^/]++)$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_not_trailing_slash_HEAD_method')), array ());
if ('HEAD' !== $requestMethod) {
$allow[] = 'HEAD';
if (!in_array($requestMethod, array('HEAD'))) {
$allow = array_merge($allow, array('HEAD'));
goto not_regex_not_trailing_slash_HEAD_method;
}
@ -229,8 +229,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
// regex_not_trailing_slash_POST_method
if (0 === strpos($pathinfo, '/not-trailing/regex/post-method') && preg_match('#^/not\\-trailing/regex/post\\-method/(?P<param>[^/]++)$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_not_trailing_slash_POST_method')), array ());
if ('POST' !== $canonicalMethod) {
$allow[] = 'POST';
if (!in_array($requestMethod, array('POST'))) {
$allow = array_merge($allow, array('POST'));
goto not_regex_not_trailing_slash_POST_method;
}