[Routing] made a small optimization to the route dumper
This commit is contained in:
parent
117321d3c6
commit
0dbfa18c46
@ -92,13 +92,23 @@ class PhpMatcherDumper extends MatcherDumper
|
||||
EOF;
|
||||
|
||||
if ($req = $route->getRequirement('_method')) {
|
||||
$req = implode('\', \'', array_map('strtolower', explode('|', $req)));
|
||||
$code[] = <<<EOF
|
||||
if (!in_array(\$this->context->getMethod(), array('$req'))) {
|
||||
\$allow = array_merge(\$allow, array('$req'));
|
||||
$methods = array_map('strtolower', explode('|', $req));
|
||||
if (1 === count($methods)) {
|
||||
$code[] = <<<EOF
|
||||
if (\$this->context->getMethod() != '$methods[0]') {
|
||||
\$allow[] = '$methods[0]';
|
||||
goto $gotoname;
|
||||
}
|
||||
EOF;
|
||||
} else {
|
||||
$methods = implode('\', \'', $methods);
|
||||
$code[] = <<<EOF
|
||||
if (!in_array(\$this->context->getMethod(), array('$methods'))) {
|
||||
\$allow = array_merge(\$allow, array('$methods'));
|
||||
goto $gotoname;
|
||||
}
|
||||
EOF;
|
||||
}
|
||||
}
|
||||
|
||||
if ($hasTrailingSlash) {
|
||||
|
@ -64,8 +64,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
|
||||
|
||||
// baz5
|
||||
if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P<foo>[^/\.]+?)/$#x', $pathinfo, $matches)) {
|
||||
if (!in_array($this->context->getMethod(), array('post'))) {
|
||||
$allow = array_merge($allow, array('post'));
|
||||
if ($this->context->getMethod() != 'post') {
|
||||
$allow[] = 'post';
|
||||
goto not_baz5;
|
||||
}
|
||||
$matches['_route'] = 'baz5';
|
||||
@ -75,8 +75,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
|
||||
|
||||
// baz.baz6
|
||||
if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P<foo>[^/\.]+?)/$#x', $pathinfo, $matches)) {
|
||||
if (!in_array($this->context->getMethod(), array('put'))) {
|
||||
$allow = array_merge($allow, array('put'));
|
||||
if ($this->context->getMethod() != 'put') {
|
||||
$allow[] = 'put';
|
||||
goto not_bazbaz6;
|
||||
}
|
||||
$matches['_route'] = 'baz.baz6';
|
||||
|
@ -70,8 +70,8 @@ class ProjectUrlMatcher extends Symfony\Tests\Component\Routing\Fixtures\Redirec
|
||||
|
||||
// baz5
|
||||
if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P<foo>[^/\.]+?)/?$#x', $pathinfo, $matches)) {
|
||||
if (!in_array($this->context->getMethod(), array('post'))) {
|
||||
$allow = array_merge($allow, array('post'));
|
||||
if ($this->context->getMethod() != 'post') {
|
||||
$allow[] = 'post';
|
||||
goto not_baz5;
|
||||
}
|
||||
if (substr($pathinfo, -1) !== '/') {
|
||||
@ -84,8 +84,8 @@ class ProjectUrlMatcher extends Symfony\Tests\Component\Routing\Fixtures\Redirec
|
||||
|
||||
// baz.baz6
|
||||
if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P<foo>[^/\.]+?)/?$#x', $pathinfo, $matches)) {
|
||||
if (!in_array($this->context->getMethod(), array('put'))) {
|
||||
$allow = array_merge($allow, array('put'));
|
||||
if ($this->context->getMethod() != 'put') {
|
||||
$allow[] = 'put';
|
||||
goto not_bazbaz6;
|
||||
}
|
||||
if (substr($pathinfo, -1) !== '/') {
|
||||
|
Reference in New Issue
Block a user