[Routing] Allow GET requests to be redirected. Fixes #23004
This commit is contained in:
parent
7a9875c3cd
commit
71d4e366a9
@ -238,7 +238,7 @@ EOF;
|
|||||||
$hostMatches = false;
|
$hostMatches = false;
|
||||||
$methods = $route->getMethods();
|
$methods = $route->getMethods();
|
||||||
|
|
||||||
$supportsTrailingSlash = $supportsRedirections && (!$methods || in_array('HEAD', $methods));
|
$supportsTrailingSlash = $supportsRedirections && (!$methods || in_array('HEAD', $methods) || in_array('GET', $methods));
|
||||||
$regex = $compiledRoute->getRegex();
|
$regex = $compiledRoute->getRegex();
|
||||||
|
|
||||||
if (!count($compiledRoute->getPathVariables()) && false !== preg_match('#^(.)\^(?P<url>.*?)\$\1#'.(substr($regex, -1) === 'u' ? 'u' : ''), $regex, $m)) {
|
if (!count($compiledRoute->getPathVariables()) && false !== preg_match('#^(.)\^(?P<url>.*?)\$\1#'.(substr($regex, -1) === 'u' ? 'u' : ''), $regex, $m)) {
|
||||||
|
@ -0,0 +1,204 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
|
||||||
|
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
|
||||||
|
use Symfony\Component\Routing\RequestContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ProjectUrlMatcher.
|
||||||
|
*
|
||||||
|
* This class has been auto-generated
|
||||||
|
* by the Symfony Routing Component.
|
||||||
|
*/
|
||||||
|
class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*/
|
||||||
|
public function __construct(RequestContext $context)
|
||||||
|
{
|
||||||
|
$this->context = $context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function match($pathinfo)
|
||||||
|
{
|
||||||
|
$allow = array();
|
||||||
|
$pathinfo = rawurldecode($pathinfo);
|
||||||
|
$trimmedPathinfo = rtrim($pathinfo, '/');
|
||||||
|
$context = $this->context;
|
||||||
|
$request = $this->request;
|
||||||
|
$requestMethod = $canonicalMethod = $context->getMethod();
|
||||||
|
$scheme = $context->getScheme();
|
||||||
|
|
||||||
|
if ('HEAD' === $requestMethod) {
|
||||||
|
$canonicalMethod = 'GET';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (0 === strpos($pathinfo, '/trailing/simple')) {
|
||||||
|
// simple_trailing_slash_no_methods
|
||||||
|
if ('/trailing/simple/no-methods/' === $pathinfo) {
|
||||||
|
return array('_route' => 'simple_trailing_slash_no_methods');
|
||||||
|
}
|
||||||
|
|
||||||
|
// simple_trailing_slash_GET_method
|
||||||
|
if ('/trailing/simple/get-method/' === $pathinfo) {
|
||||||
|
if ('GET' !== $canonicalMethod) {
|
||||||
|
$allow[] = 'GET';
|
||||||
|
goto not_simple_trailing_slash_GET_method;
|
||||||
|
}
|
||||||
|
|
||||||
|
return array('_route' => 'simple_trailing_slash_GET_method');
|
||||||
|
}
|
||||||
|
not_simple_trailing_slash_GET_method:
|
||||||
|
|
||||||
|
// simple_trailing_slash_HEAD_method
|
||||||
|
if ('/trailing/simple/head-method/' === $pathinfo) {
|
||||||
|
if ('HEAD' !== $requestMethod) {
|
||||||
|
$allow[] = 'HEAD';
|
||||||
|
goto not_simple_trailing_slash_HEAD_method;
|
||||||
|
}
|
||||||
|
|
||||||
|
return array('_route' => 'simple_trailing_slash_HEAD_method');
|
||||||
|
}
|
||||||
|
not_simple_trailing_slash_HEAD_method:
|
||||||
|
|
||||||
|
// simple_trailing_slash_POST_method
|
||||||
|
if ('/trailing/simple/post-method/' === $pathinfo) {
|
||||||
|
if ('POST' !== $canonicalMethod) {
|
||||||
|
$allow[] = 'POST';
|
||||||
|
goto not_simple_trailing_slash_POST_method;
|
||||||
|
}
|
||||||
|
|
||||||
|
return array('_route' => 'simple_trailing_slash_POST_method');
|
||||||
|
}
|
||||||
|
not_simple_trailing_slash_POST_method:
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
elseif (0 === strpos($pathinfo, '/trailing/regex')) {
|
||||||
|
// regex_trailing_slash_no_methods
|
||||||
|
if (0 === strpos($pathinfo, '/trailing/regex/no-methods') && preg_match('#^/trailing/regex/no\\-methods/(?P<param>[^/]++)/$#s', $pathinfo, $matches)) {
|
||||||
|
return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_no_methods')), array ());
|
||||||
|
}
|
||||||
|
|
||||||
|
// regex_trailing_slash_GET_method
|
||||||
|
if (0 === strpos($pathinfo, '/trailing/regex/get-method') && preg_match('#^/trailing/regex/get\\-method/(?P<param>[^/]++)/$#s', $pathinfo, $matches)) {
|
||||||
|
if ('GET' !== $canonicalMethod) {
|
||||||
|
$allow[] = 'GET';
|
||||||
|
goto not_regex_trailing_slash_GET_method;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_GET_method')), array ());
|
||||||
|
}
|
||||||
|
not_regex_trailing_slash_GET_method:
|
||||||
|
|
||||||
|
// regex_trailing_slash_HEAD_method
|
||||||
|
if (0 === strpos($pathinfo, '/trailing/regex/head-method') && preg_match('#^/trailing/regex/head\\-method/(?P<param>[^/]++)/$#s', $pathinfo, $matches)) {
|
||||||
|
if ('HEAD' !== $requestMethod) {
|
||||||
|
$allow[] = 'HEAD';
|
||||||
|
goto not_regex_trailing_slash_HEAD_method;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_HEAD_method')), array ());
|
||||||
|
}
|
||||||
|
not_regex_trailing_slash_HEAD_method:
|
||||||
|
|
||||||
|
// regex_trailing_slash_POST_method
|
||||||
|
if (0 === strpos($pathinfo, '/trailing/regex/post-method') && preg_match('#^/trailing/regex/post\\-method/(?P<param>[^/]++)/$#s', $pathinfo, $matches)) {
|
||||||
|
if ('POST' !== $canonicalMethod) {
|
||||||
|
$allow[] = 'POST';
|
||||||
|
goto not_regex_trailing_slash_POST_method;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_POST_method')), array ());
|
||||||
|
}
|
||||||
|
not_regex_trailing_slash_POST_method:
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
elseif (0 === strpos($pathinfo, '/not-trailing/simple')) {
|
||||||
|
// simple_not_trailing_slash_no_methods
|
||||||
|
if ('/not-trailing/simple/no-methods' === $pathinfo) {
|
||||||
|
return array('_route' => 'simple_not_trailing_slash_no_methods');
|
||||||
|
}
|
||||||
|
|
||||||
|
// simple_not_trailing_slash_GET_method
|
||||||
|
if ('/not-trailing/simple/get-method' === $pathinfo) {
|
||||||
|
if ('GET' !== $canonicalMethod) {
|
||||||
|
$allow[] = 'GET';
|
||||||
|
goto not_simple_not_trailing_slash_GET_method;
|
||||||
|
}
|
||||||
|
|
||||||
|
return array('_route' => 'simple_not_trailing_slash_GET_method');
|
||||||
|
}
|
||||||
|
not_simple_not_trailing_slash_GET_method:
|
||||||
|
|
||||||
|
// simple_not_trailing_slash_HEAD_method
|
||||||
|
if ('/not-trailing/simple/head-method' === $pathinfo) {
|
||||||
|
if ('HEAD' !== $requestMethod) {
|
||||||
|
$allow[] = 'HEAD';
|
||||||
|
goto not_simple_not_trailing_slash_HEAD_method;
|
||||||
|
}
|
||||||
|
|
||||||
|
return array('_route' => 'simple_not_trailing_slash_HEAD_method');
|
||||||
|
}
|
||||||
|
not_simple_not_trailing_slash_HEAD_method:
|
||||||
|
|
||||||
|
// simple_not_trailing_slash_POST_method
|
||||||
|
if ('/not-trailing/simple/post-method' === $pathinfo) {
|
||||||
|
if ('POST' !== $canonicalMethod) {
|
||||||
|
$allow[] = 'POST';
|
||||||
|
goto not_simple_not_trailing_slash_POST_method;
|
||||||
|
}
|
||||||
|
|
||||||
|
return array('_route' => 'simple_not_trailing_slash_POST_method');
|
||||||
|
}
|
||||||
|
not_simple_not_trailing_slash_POST_method:
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
elseif (0 === strpos($pathinfo, '/not-trailing/regex')) {
|
||||||
|
// regex_not_trailing_slash_no_methods
|
||||||
|
if (0 === strpos($pathinfo, '/not-trailing/regex/no-methods') && preg_match('#^/not\\-trailing/regex/no\\-methods/(?P<param>[^/]++)$#s', $pathinfo, $matches)) {
|
||||||
|
return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_not_trailing_slash_no_methods')), array ());
|
||||||
|
}
|
||||||
|
|
||||||
|
// regex_not_trailing_slash_GET_method
|
||||||
|
if (0 === strpos($pathinfo, '/not-trailing/regex/get-method') && preg_match('#^/not\\-trailing/regex/get\\-method/(?P<param>[^/]++)$#s', $pathinfo, $matches)) {
|
||||||
|
if ('GET' !== $canonicalMethod) {
|
||||||
|
$allow[] = 'GET';
|
||||||
|
goto not_regex_not_trailing_slash_GET_method;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_not_trailing_slash_GET_method')), array ());
|
||||||
|
}
|
||||||
|
not_regex_not_trailing_slash_GET_method:
|
||||||
|
|
||||||
|
// regex_not_trailing_slash_HEAD_method
|
||||||
|
if (0 === strpos($pathinfo, '/not-trailing/regex/head-method') && preg_match('#^/not\\-trailing/regex/head\\-method/(?P<param>[^/]++)$#s', $pathinfo, $matches)) {
|
||||||
|
if ('HEAD' !== $requestMethod) {
|
||||||
|
$allow[] = 'HEAD';
|
||||||
|
goto not_regex_not_trailing_slash_HEAD_method;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_not_trailing_slash_HEAD_method')), array ());
|
||||||
|
}
|
||||||
|
not_regex_not_trailing_slash_HEAD_method:
|
||||||
|
|
||||||
|
// regex_not_trailing_slash_POST_method
|
||||||
|
if (0 === strpos($pathinfo, '/not-trailing/regex/post-method') && preg_match('#^/not\\-trailing/regex/post\\-method/(?P<param>[^/]++)$#s', $pathinfo, $matches)) {
|
||||||
|
if ('POST' !== $canonicalMethod) {
|
||||||
|
$allow[] = 'POST';
|
||||||
|
goto not_regex_not_trailing_slash_POST_method;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_not_trailing_slash_POST_method')), array ());
|
||||||
|
}
|
||||||
|
not_regex_not_trailing_slash_POST_method:
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,228 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
|
||||||
|
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
|
||||||
|
use Symfony\Component\Routing\RequestContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ProjectUrlMatcher.
|
||||||
|
*
|
||||||
|
* This class has been auto-generated
|
||||||
|
* by the Symfony Routing Component.
|
||||||
|
*/
|
||||||
|
class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\RedirectableUrlMatcher
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*/
|
||||||
|
public function __construct(RequestContext $context)
|
||||||
|
{
|
||||||
|
$this->context = $context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function match($pathinfo)
|
||||||
|
{
|
||||||
|
$allow = array();
|
||||||
|
$pathinfo = rawurldecode($pathinfo);
|
||||||
|
$trimmedPathinfo = rtrim($pathinfo, '/');
|
||||||
|
$context = $this->context;
|
||||||
|
$request = $this->request;
|
||||||
|
$requestMethod = $canonicalMethod = $context->getMethod();
|
||||||
|
$scheme = $context->getScheme();
|
||||||
|
|
||||||
|
if ('HEAD' === $requestMethod) {
|
||||||
|
$canonicalMethod = 'GET';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (0 === strpos($pathinfo, '/trailing/simple')) {
|
||||||
|
// simple_trailing_slash_no_methods
|
||||||
|
if ('/trailing/simple/no-methods' === $trimmedPathinfo) {
|
||||||
|
if (substr($pathinfo, -1) !== '/') {
|
||||||
|
return $this->redirect($pathinfo.'/', 'simple_trailing_slash_no_methods');
|
||||||
|
}
|
||||||
|
|
||||||
|
return array('_route' => 'simple_trailing_slash_no_methods');
|
||||||
|
}
|
||||||
|
|
||||||
|
// simple_trailing_slash_GET_method
|
||||||
|
if ('/trailing/simple/get-method' === $trimmedPathinfo) {
|
||||||
|
if ('GET' !== $canonicalMethod) {
|
||||||
|
$allow[] = 'GET';
|
||||||
|
goto not_simple_trailing_slash_GET_method;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (substr($pathinfo, -1) !== '/') {
|
||||||
|
return $this->redirect($pathinfo.'/', 'simple_trailing_slash_GET_method');
|
||||||
|
}
|
||||||
|
|
||||||
|
return array('_route' => 'simple_trailing_slash_GET_method');
|
||||||
|
}
|
||||||
|
not_simple_trailing_slash_GET_method:
|
||||||
|
|
||||||
|
// simple_trailing_slash_HEAD_method
|
||||||
|
if ('/trailing/simple/head-method' === $trimmedPathinfo) {
|
||||||
|
if ('HEAD' !== $requestMethod) {
|
||||||
|
$allow[] = 'HEAD';
|
||||||
|
goto not_simple_trailing_slash_HEAD_method;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (substr($pathinfo, -1) !== '/') {
|
||||||
|
return $this->redirect($pathinfo.'/', 'simple_trailing_slash_HEAD_method');
|
||||||
|
}
|
||||||
|
|
||||||
|
return array('_route' => 'simple_trailing_slash_HEAD_method');
|
||||||
|
}
|
||||||
|
not_simple_trailing_slash_HEAD_method:
|
||||||
|
|
||||||
|
// simple_trailing_slash_POST_method
|
||||||
|
if ('/trailing/simple/post-method/' === $pathinfo) {
|
||||||
|
if ('POST' !== $canonicalMethod) {
|
||||||
|
$allow[] = 'POST';
|
||||||
|
goto not_simple_trailing_slash_POST_method;
|
||||||
|
}
|
||||||
|
|
||||||
|
return array('_route' => 'simple_trailing_slash_POST_method');
|
||||||
|
}
|
||||||
|
not_simple_trailing_slash_POST_method:
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
elseif (0 === strpos($pathinfo, '/trailing/regex')) {
|
||||||
|
// regex_trailing_slash_no_methods
|
||||||
|
if (0 === strpos($pathinfo, '/trailing/regex/no-methods') && preg_match('#^/trailing/regex/no\\-methods/(?P<param>[^/]++)/?$#s', $pathinfo, $matches)) {
|
||||||
|
if (substr($pathinfo, -1) !== '/') {
|
||||||
|
return $this->redirect($pathinfo.'/', 'regex_trailing_slash_no_methods');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_no_methods')), array ());
|
||||||
|
}
|
||||||
|
|
||||||
|
// regex_trailing_slash_GET_method
|
||||||
|
if (0 === strpos($pathinfo, '/trailing/regex/get-method') && preg_match('#^/trailing/regex/get\\-method/(?P<param>[^/]++)/?$#s', $pathinfo, $matches)) {
|
||||||
|
if ('GET' !== $canonicalMethod) {
|
||||||
|
$allow[] = 'GET';
|
||||||
|
goto not_regex_trailing_slash_GET_method;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (substr($pathinfo, -1) !== '/') {
|
||||||
|
return $this->redirect($pathinfo.'/', 'regex_trailing_slash_GET_method');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_GET_method')), array ());
|
||||||
|
}
|
||||||
|
not_regex_trailing_slash_GET_method:
|
||||||
|
|
||||||
|
// regex_trailing_slash_HEAD_method
|
||||||
|
if (0 === strpos($pathinfo, '/trailing/regex/head-method') && preg_match('#^/trailing/regex/head\\-method/(?P<param>[^/]++)/?$#s', $pathinfo, $matches)) {
|
||||||
|
if ('HEAD' !== $requestMethod) {
|
||||||
|
$allow[] = 'HEAD';
|
||||||
|
goto not_regex_trailing_slash_HEAD_method;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (substr($pathinfo, -1) !== '/') {
|
||||||
|
return $this->redirect($pathinfo.'/', 'regex_trailing_slash_HEAD_method');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_HEAD_method')), array ());
|
||||||
|
}
|
||||||
|
not_regex_trailing_slash_HEAD_method:
|
||||||
|
|
||||||
|
// regex_trailing_slash_POST_method
|
||||||
|
if (0 === strpos($pathinfo, '/trailing/regex/post-method') && preg_match('#^/trailing/regex/post\\-method/(?P<param>[^/]++)/$#s', $pathinfo, $matches)) {
|
||||||
|
if ('POST' !== $canonicalMethod) {
|
||||||
|
$allow[] = 'POST';
|
||||||
|
goto not_regex_trailing_slash_POST_method;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_POST_method')), array ());
|
||||||
|
}
|
||||||
|
not_regex_trailing_slash_POST_method:
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
elseif (0 === strpos($pathinfo, '/not-trailing/simple')) {
|
||||||
|
// simple_not_trailing_slash_no_methods
|
||||||
|
if ('/not-trailing/simple/no-methods' === $pathinfo) {
|
||||||
|
return array('_route' => 'simple_not_trailing_slash_no_methods');
|
||||||
|
}
|
||||||
|
|
||||||
|
// simple_not_trailing_slash_GET_method
|
||||||
|
if ('/not-trailing/simple/get-method' === $pathinfo) {
|
||||||
|
if ('GET' !== $canonicalMethod) {
|
||||||
|
$allow[] = 'GET';
|
||||||
|
goto not_simple_not_trailing_slash_GET_method;
|
||||||
|
}
|
||||||
|
|
||||||
|
return array('_route' => 'simple_not_trailing_slash_GET_method');
|
||||||
|
}
|
||||||
|
not_simple_not_trailing_slash_GET_method:
|
||||||
|
|
||||||
|
// simple_not_trailing_slash_HEAD_method
|
||||||
|
if ('/not-trailing/simple/head-method' === $pathinfo) {
|
||||||
|
if ('HEAD' !== $requestMethod) {
|
||||||
|
$allow[] = 'HEAD';
|
||||||
|
goto not_simple_not_trailing_slash_HEAD_method;
|
||||||
|
}
|
||||||
|
|
||||||
|
return array('_route' => 'simple_not_trailing_slash_HEAD_method');
|
||||||
|
}
|
||||||
|
not_simple_not_trailing_slash_HEAD_method:
|
||||||
|
|
||||||
|
// simple_not_trailing_slash_POST_method
|
||||||
|
if ('/not-trailing/simple/post-method' === $pathinfo) {
|
||||||
|
if ('POST' !== $canonicalMethod) {
|
||||||
|
$allow[] = 'POST';
|
||||||
|
goto not_simple_not_trailing_slash_POST_method;
|
||||||
|
}
|
||||||
|
|
||||||
|
return array('_route' => 'simple_not_trailing_slash_POST_method');
|
||||||
|
}
|
||||||
|
not_simple_not_trailing_slash_POST_method:
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
elseif (0 === strpos($pathinfo, '/not-trailing/regex')) {
|
||||||
|
// regex_not_trailing_slash_no_methods
|
||||||
|
if (0 === strpos($pathinfo, '/not-trailing/regex/no-methods') && preg_match('#^/not\\-trailing/regex/no\\-methods/(?P<param>[^/]++)$#s', $pathinfo, $matches)) {
|
||||||
|
return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_not_trailing_slash_no_methods')), array ());
|
||||||
|
}
|
||||||
|
|
||||||
|
// regex_not_trailing_slash_GET_method
|
||||||
|
if (0 === strpos($pathinfo, '/not-trailing/regex/get-method') && preg_match('#^/not\\-trailing/regex/get\\-method/(?P<param>[^/]++)$#s', $pathinfo, $matches)) {
|
||||||
|
if ('GET' !== $canonicalMethod) {
|
||||||
|
$allow[] = 'GET';
|
||||||
|
goto not_regex_not_trailing_slash_GET_method;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_not_trailing_slash_GET_method')), array ());
|
||||||
|
}
|
||||||
|
not_regex_not_trailing_slash_GET_method:
|
||||||
|
|
||||||
|
// regex_not_trailing_slash_HEAD_method
|
||||||
|
if (0 === strpos($pathinfo, '/not-trailing/regex/head-method') && preg_match('#^/not\\-trailing/regex/head\\-method/(?P<param>[^/]++)$#s', $pathinfo, $matches)) {
|
||||||
|
if ('HEAD' !== $requestMethod) {
|
||||||
|
$allow[] = 'HEAD';
|
||||||
|
goto not_regex_not_trailing_slash_HEAD_method;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_not_trailing_slash_HEAD_method')), array ());
|
||||||
|
}
|
||||||
|
not_regex_not_trailing_slash_HEAD_method:
|
||||||
|
|
||||||
|
// regex_not_trailing_slash_POST_method
|
||||||
|
if (0 === strpos($pathinfo, '/not-trailing/regex/post-method') && preg_match('#^/not\\-trailing/regex/post\\-method/(?P<param>[^/]++)$#s', $pathinfo, $matches)) {
|
||||||
|
if ('POST' !== $canonicalMethod) {
|
||||||
|
$allow[] = 'POST';
|
||||||
|
goto not_regex_not_trailing_slash_POST_method;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_not_trailing_slash_POST_method')), array ());
|
||||||
|
}
|
||||||
|
not_regex_not_trailing_slash_POST_method:
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException();
|
||||||
|
}
|
||||||
|
}
|
@ -345,12 +345,33 @@ class PhpMatcherDumperTest extends TestCase
|
|||||||
$groupOptimisedCollection->add('slashed_b', new Route('/slashed/group/b/'));
|
$groupOptimisedCollection->add('slashed_b', new Route('/slashed/group/b/'));
|
||||||
$groupOptimisedCollection->add('slashed_c', new Route('/slashed/group/c/'));
|
$groupOptimisedCollection->add('slashed_c', new Route('/slashed/group/c/'));
|
||||||
|
|
||||||
|
$trailingSlashCollection = new RouteCollection();
|
||||||
|
$trailingSlashCollection->add('simple_trailing_slash_no_methods', new Route('/trailing/simple/no-methods/', array(), array(), array(), '', array(), array()));
|
||||||
|
$trailingSlashCollection->add('simple_trailing_slash_GET_method', new Route('/trailing/simple/get-method/', array(), array(), array(), '', array(), array('GET')));
|
||||||
|
$trailingSlashCollection->add('simple_trailing_slash_HEAD_method', new Route('/trailing/simple/head-method/', array(), array(), array(), '', array(), array('HEAD')));
|
||||||
|
$trailingSlashCollection->add('simple_trailing_slash_POST_method', new Route('/trailing/simple/post-method/', array(), array(), array(), '', array(), array('POST')));
|
||||||
|
$trailingSlashCollection->add('regex_trailing_slash_no_methods', new Route('/trailing/regex/no-methods/{param}/', array(), array(), array(), '', array(), array()));
|
||||||
|
$trailingSlashCollection->add('regex_trailing_slash_GET_method', new Route('/trailing/regex/get-method/{param}/', array(), array(), array(), '', array(), array('GET')));
|
||||||
|
$trailingSlashCollection->add('regex_trailing_slash_HEAD_method', new Route('/trailing/regex/head-method/{param}/', array(), array(), array(), '', array(), array('HEAD')));
|
||||||
|
$trailingSlashCollection->add('regex_trailing_slash_POST_method', new Route('/trailing/regex/post-method/{param}/', array(), array(), array(), '', array(), array('POST')));
|
||||||
|
|
||||||
|
$trailingSlashCollection->add('simple_not_trailing_slash_no_methods', new Route('/not-trailing/simple/no-methods', array(), array(), array(), '', array(), array()));
|
||||||
|
$trailingSlashCollection->add('simple_not_trailing_slash_GET_method', new Route('/not-trailing/simple/get-method', array(), array(), array(), '', array(), array('GET')));
|
||||||
|
$trailingSlashCollection->add('simple_not_trailing_slash_HEAD_method', new Route('/not-trailing/simple/head-method', array(), array(), array(), '', array(), array('HEAD')));
|
||||||
|
$trailingSlashCollection->add('simple_not_trailing_slash_POST_method', new Route('/not-trailing/simple/post-method', array(), array(), array(), '', array(), array('POST')));
|
||||||
|
$trailingSlashCollection->add('regex_not_trailing_slash_no_methods', new Route('/not-trailing/regex/no-methods/{param}', array(), array(), array(), '', array(), array()));
|
||||||
|
$trailingSlashCollection->add('regex_not_trailing_slash_GET_method', new Route('/not-trailing/regex/get-method/{param}', array(), array(), array(), '', array(), array('GET')));
|
||||||
|
$trailingSlashCollection->add('regex_not_trailing_slash_HEAD_method', new Route('/not-trailing/regex/head-method/{param}', array(), array(), array(), '', array(), array('HEAD')));
|
||||||
|
$trailingSlashCollection->add('regex_not_trailing_slash_POST_method', new Route('/not-trailing/regex/post-method/{param}', array(), array(), array(), '', array(), array('POST')));
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
array($collection, 'url_matcher1.php', array()),
|
array($collection, 'url_matcher1.php', array()),
|
||||||
array($redirectCollection, 'url_matcher2.php', array('base_class' => 'Symfony\Component\Routing\Tests\Fixtures\RedirectableUrlMatcher')),
|
array($redirectCollection, 'url_matcher2.php', array('base_class' => 'Symfony\Component\Routing\Tests\Fixtures\RedirectableUrlMatcher')),
|
||||||
array($rootprefixCollection, 'url_matcher3.php', array()),
|
array($rootprefixCollection, 'url_matcher3.php', array()),
|
||||||
array($headMatchCasesCollection, 'url_matcher4.php', array()),
|
array($headMatchCasesCollection, 'url_matcher4.php', array()),
|
||||||
array($groupOptimisedCollection, 'url_matcher5.php', array('base_class' => 'Symfony\Component\Routing\Tests\Fixtures\RedirectableUrlMatcher')),
|
array($groupOptimisedCollection, 'url_matcher5.php', array('base_class' => 'Symfony\Component\Routing\Tests\Fixtures\RedirectableUrlMatcher')),
|
||||||
|
array($trailingSlashCollection, 'url_matcher6.php', array()),
|
||||||
|
array($trailingSlashCollection, 'url_matcher7.php', array('base_class' => 'Symfony\Component\Routing\Tests\Fixtures\RedirectableUrlMatcher')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user