composer update

This commit is contained in:
Manish Verma
2018-12-05 10:50:52 +05:30
parent 9eabcacfa7
commit 4addd1e9c6
3328 changed files with 156676 additions and 138988 deletions

View File

@@ -5,7 +5,7 @@ namespace Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/here", name="lol")
* @Route("/here", name="lol", methods={"GET", "POST"}, schemes={"https"})
*/
class InvokableController
{

View File

@@ -0,0 +1,27 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/", requirements={"foo", "\d+"})
*/
class RequirementsWithoutPlaceholderNameController
{
/**
* @Route("/{foo}", name="foo", requirements={"foo", "\d+"})
*/
public function foo()
{
}
}

View File

@@ -1,7 +1,6 @@
<?php
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherTrait;
use Symfony\Component\Routing\RequestContext;
/**
@@ -10,26 +9,10 @@ use Symfony\Component\Routing\RequestContext;
*/
class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
{
use PhpMatcherTrait;
public function __construct(RequestContext $context)
{
$this->context = $context;
}
public function match($rawPathinfo)
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo);
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
if ('HEAD' === $requestMethod) {
$canonicalMethod = 'GET';
}
if ('/' === $pathinfo && !$allow && !$allowSchemes) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}
throw $allow ? new MethodNotAllowedException(array_keys($allow)) : new ResourceNotFoundException();
}
}

View File

@@ -1,7 +1,6 @@
<?php
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherTrait;
use Symfony\Component\Routing\RequestContext;
/**
@@ -10,77 +9,32 @@ use Symfony\Component\Routing\RequestContext;
*/
class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
{
use PhpMatcherTrait;
public function __construct(RequestContext $context)
{
$this->context = $context;
}
public function match($rawPathinfo)
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo);
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
$host = strtolower($context->getHost());
if ('HEAD' === $requestMethod) {
$canonicalMethod = 'GET';
}
switch ($pathinfo) {
default:
$routes = array(
'/test/baz' => array(array('_route' => 'baz'), null, null, null),
'/test/baz.html' => array(array('_route' => 'baz2'), null, null, null),
'/test/baz3/' => array(array('_route' => 'baz3'), null, null, null),
'/foofoo' => array(array('_route' => 'foofoo', 'def' => 'test'), null, null, null),
'/spa ce' => array(array('_route' => 'space'), null, null, null),
'/multi/new' => array(array('_route' => 'overridden2'), null, null, null),
'/multi/hey/' => array(array('_route' => 'hey'), null, null, null),
'/ababa' => array(array('_route' => 'ababa'), null, null, null),
'/route1' => array(array('_route' => 'route1'), 'a.example.com', null, null),
'/c2/route2' => array(array('_route' => 'route2'), 'a.example.com', null, null),
'/route4' => array(array('_route' => 'route4'), 'a.example.com', null, null),
'/c2/route3' => array(array('_route' => 'route3'), 'b.example.com', null, null),
'/route5' => array(array('_route' => 'route5'), 'c.example.com', null, null),
'/route6' => array(array('_route' => 'route6'), null, null, null),
'/route11' => array(array('_route' => 'route11'), '#^(?P<var1>[^\\.]++)\\.example\\.com$#sDi', null, null),
'/route12' => array(array('_route' => 'route12', 'var1' => 'val'), '#^(?P<var1>[^\\.]++)\\.example\\.com$#sDi', null, null),
'/route17' => array(array('_route' => 'route17'), null, null, null),
);
if (!isset($routes[$pathinfo])) {
break;
}
list($ret, $requiredHost, $requiredMethods, $requiredSchemes) = $routes[$pathinfo];
if ($requiredHost) {
if ('#' !== $requiredHost[0] ? $requiredHost !== $host : !preg_match($requiredHost, $host, $hostMatches)) {
break;
}
if ('#' === $requiredHost[0] && $hostMatches) {
$hostMatches['_route'] = $ret['_route'];
$ret = $this->mergeDefaults($hostMatches, $ret);
}
}
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
if ($hasRequiredScheme) {
$allow += $requiredMethods;
}
break;
}
if (!$hasRequiredScheme) {
$allowSchemes += $requiredSchemes;
break;
}
return $ret;
}
$matchedPathinfo = $host.'.'.$pathinfo;
$regexList = array(
$this->matchHost = true;
$this->staticRoutes = array(
'/test/baz' => array(array(array('_route' => 'baz'), null, null, null, false, null)),
'/test/baz.html' => array(array(array('_route' => 'baz2'), null, null, null, false, null)),
'/test/baz3' => array(array(array('_route' => 'baz3'), null, null, null, true, null)),
'/foofoo' => array(array(array('_route' => 'foofoo', 'def' => 'test'), null, null, null, false, null)),
'/spa ce' => array(array(array('_route' => 'space'), null, null, null, false, null)),
'/multi/new' => array(array(array('_route' => 'overridden2'), null, null, null, false, null)),
'/multi/hey' => array(array(array('_route' => 'hey'), null, null, null, true, null)),
'/ababa' => array(array(array('_route' => 'ababa'), null, null, null, false, null)),
'/route1' => array(array(array('_route' => 'route1'), 'a.example.com', null, null, false, null)),
'/c2/route2' => array(array(array('_route' => 'route2'), 'a.example.com', null, null, false, null)),
'/route4' => array(array(array('_route' => 'route4'), 'a.example.com', null, null, false, null)),
'/c2/route3' => array(array(array('_route' => 'route3'), 'b.example.com', null, null, false, null)),
'/route5' => array(array(array('_route' => 'route5'), 'c.example.com', null, null, false, null)),
'/route6' => array(array(array('_route' => 'route6'), null, null, null, false, null)),
'/route11' => array(array(array('_route' => 'route11'), '#^(?P<var1>[^\\.]++)\\.example\\.com$#sDi', null, null, false, null)),
'/route12' => array(array(array('_route' => 'route12', 'var1' => 'val'), '#^(?P<var1>[^\\.]++)\\.example\\.com$#sDi', null, null, false, null)),
'/route17' => array(array(array('_route' => 'route17'), null, null, null, false, null)),
);
$this->regexpList = array(
0 => '{^(?'
.'|(?:(?:[^./]*+\\.)++)(?'
.'|/foo/(baz|symfony)(*:47)'
@@ -88,160 +42,72 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
.'|/([^/]++)(*:70)'
.'|head/([^/]++)(*:90)'
.')'
.'|/test/([^/]++)/(?'
.'|(*:116)'
.'|/test/([^/]++)(?'
.'|(*:115)'
.')'
.'|/([\']+)(*:132)'
.'|/([\']+)(*:131)'
.'|/a/(?'
.'|b\'b/([^/]++)(?'
.'|(*:161)'
.'|(*:169)'
.'|(*:160)'
.'|(*:168)'
.')'
.'|(.*)(*:182)'
.'|(.*)(*:181)'
.'|b\'b/([^/]++)(?'
.'|(*:205)'
.'|(*:213)'
.'|(*:204)'
.'|(*:212)'
.')'
.')'
.'|/multi/hello(?:/([^/]++))?(*:249)'
.'|/multi/hello(?:/([^/]++))?(*:248)'
.'|/([^/]++)/b/([^/]++)(?'
.'|(*:280)'
.'|(*:288)'
.'|(*:279)'
.'|(*:287)'
.')'
.'|/aba/([^/]++)(*:310)'
.'|/aba/([^/]++)(*:309)'
.')|(?i:([^\\.]++)\\.example\\.com)\\.(?'
.'|/route1(?'
.'|3/([^/]++)(*:372)'
.'|4/([^/]++)(*:390)'
.'|3/([^/]++)(*:371)'
.'|4/([^/]++)(*:389)'
.')'
.')|(?i:c\\.example\\.com)\\.(?'
.'|/route15/([^/]++)(*:442)'
.'|/route15/([^/]++)(*:441)'
.')|(?:(?:[^./]*+\\.)++)(?'
.'|/route16/([^/]++)(*:490)'
.'|/route16/([^/]++)(*:489)'
.'|/a/(?'
.'|a\\.\\.\\.(*:511)'
.'|a\\.\\.\\.(*:510)'
.'|b/(?'
.'|([^/]++)(*:532)'
.'|c/([^/]++)(*:550)'
.'|([^/]++)(*:531)'
.'|c/([^/]++)(*:549)'
.')'
.')'
.')'
.')$}sD',
.')(?:/?)$}sD',
);
$this->dynamicRoutes = array(
47 => array(array(array('_route' => 'foo', 'def' => 'test'), array('bar'), null, null, false, null)),
70 => array(array(array('_route' => 'bar'), array('foo'), array('GET' => 0, 'HEAD' => 1), null, false, null)),
90 => array(array(array('_route' => 'barhead'), array('foo'), array('GET' => 0), null, false, null)),
115 => array(
array(array('_route' => 'baz4'), array('foo'), null, null, true, null),
array(array('_route' => 'baz5'), array('foo'), array('POST' => 0), null, true, null),
array(array('_route' => 'baz.baz6'), array('foo'), array('PUT' => 0), null, true, null),
),
131 => array(array(array('_route' => 'quoter'), array('quoter'), null, null, false, null)),
160 => array(array(array('_route' => 'foo1'), array('foo'), array('PUT' => 0), null, false, null)),
168 => array(array(array('_route' => 'bar1'), array('bar'), null, null, false, null)),
181 => array(array(array('_route' => 'overridden'), array('var'), null, null, false, null)),
204 => array(array(array('_route' => 'foo2'), array('foo1'), null, null, false, null)),
212 => array(array(array('_route' => 'bar2'), array('bar1'), null, null, false, null)),
248 => array(array(array('_route' => 'helloWorld', 'who' => 'World!'), array('who'), null, null, false, null)),
279 => array(array(array('_route' => 'foo3'), array('_locale', 'foo'), null, null, false, null)),
287 => array(array(array('_route' => 'bar3'), array('_locale', 'bar'), null, null, false, null)),
309 => array(array(array('_route' => 'foo4'), array('foo'), null, null, false, null)),
371 => array(array(array('_route' => 'route13'), array('var1', 'name'), null, null, false, null)),
389 => array(array(array('_route' => 'route14', 'var1' => 'val'), array('var1', 'name'), null, null, false, null)),
441 => array(array(array('_route' => 'route15'), array('name'), null, null, false, null)),
489 => array(array(array('_route' => 'route16', 'var1' => 'val'), array('name'), null, null, false, null)),
510 => array(array(array('_route' => 'a'), array(), null, null, false, null)),
531 => array(array(array('_route' => 'b'), array('var'), null, null, false, null)),
549 => array(array(array('_route' => 'c'), array('var'), null, null, false, null)),
);
foreach ($regexList as $offset => $regex) {
while (preg_match($regex, $matchedPathinfo, $matches)) {
switch ($m = (int) $matches['MARK']) {
case 116:
$matches = array('foo' => $matches[1] ?? null);
// baz4
return $this->mergeDefaults(array('_route' => 'baz4') + $matches, array());
// baz5
$ret = $this->mergeDefaults(array('_route' => 'baz5') + $matches, array());
if (!isset(($a = array('POST' => 0))[$requestMethod])) {
$allow += $a;
goto not_baz5;
}
return $ret;
not_baz5:
// baz.baz6
$ret = $this->mergeDefaults(array('_route' => 'baz.baz6') + $matches, array());
if (!isset(($a = array('PUT' => 0))[$requestMethod])) {
$allow += $a;
goto not_bazbaz6;
}
return $ret;
not_bazbaz6:
break;
case 161:
$matches = array('foo' => $matches[1] ?? null);
// foo1
$ret = $this->mergeDefaults(array('_route' => 'foo1') + $matches, array());
if (!isset(($a = array('PUT' => 0))[$requestMethod])) {
$allow += $a;
goto not_foo1;
}
return $ret;
not_foo1:
break;
case 205:
$matches = array('foo1' => $matches[1] ?? null);
// foo2
return $this->mergeDefaults(array('_route' => 'foo2') + $matches, array());
break;
case 280:
$matches = array('_locale' => $matches[1] ?? null, 'foo' => $matches[2] ?? null);
// foo3
return $this->mergeDefaults(array('_route' => 'foo3') + $matches, array());
break;
default:
$routes = array(
47 => array(array('_route' => 'foo', 'def' => 'test'), array('bar'), null, null),
70 => array(array('_route' => 'bar'), array('foo'), array('GET' => 0, 'HEAD' => 1), null),
90 => array(array('_route' => 'barhead'), array('foo'), array('GET' => 0), null),
132 => array(array('_route' => 'quoter'), array('quoter'), null, null),
169 => array(array('_route' => 'bar1'), array('bar'), null, null),
182 => array(array('_route' => 'overridden'), array('var'), null, null),
213 => array(array('_route' => 'bar2'), array('bar1'), null, null),
249 => array(array('_route' => 'helloWorld', 'who' => 'World!'), array('who'), null, null),
288 => array(array('_route' => 'bar3'), array('_locale', 'bar'), null, null),
310 => array(array('_route' => 'foo4'), array('foo'), null, null),
372 => array(array('_route' => 'route13'), array('var1', 'name'), null, null),
390 => array(array('_route' => 'route14', 'var1' => 'val'), array('var1', 'name'), null, null),
442 => array(array('_route' => 'route15'), array('name'), null, null),
490 => array(array('_route' => 'route16', 'var1' => 'val'), array('name'), null, null),
511 => array(array('_route' => 'a'), array(), null, null),
532 => array(array('_route' => 'b'), array('var'), null, null),
550 => array(array('_route' => 'c'), array('var'), null, null),
);
list($ret, $vars, $requiredMethods, $requiredSchemes) = $routes[$m];
foreach ($vars as $i => $v) {
if (isset($matches[1 + $i])) {
$ret[$v] = $matches[1 + $i];
}
}
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
if ($hasRequiredScheme) {
$allow += $requiredMethods;
}
break;
}
if (!$hasRequiredScheme) {
$allowSchemes += $requiredSchemes;
break;
}
return $ret;
}
if (550 === $m) {
break;
}
$regex = substr_replace($regex, 'F', $m - $offset, 1 + strlen($m));
$offset += strlen($m);
}
}
if ('/' === $pathinfo && !$allow && !$allowSchemes) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}
throw $allow ? new MethodNotAllowedException(array_keys($allow)) : new ResourceNotFoundException();
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,6 @@
<?php
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherTrait;
use Symfony\Component\Routing\RequestContext;
/**
@@ -10,142 +9,58 @@ use Symfony\Component\Routing\RequestContext;
*/
class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\RedirectableUrlMatcher
{
use PhpMatcherTrait;
public function __construct(RequestContext $context)
{
$this->context = $context;
}
public function match($pathinfo)
{
$allow = $allowSchemes = array();
if ($ret = $this->doMatch($pathinfo, $allow, $allowSchemes)) {
return $ret;
}
if ($allow) {
throw new MethodNotAllowedException(array_keys($allow));
}
if (!in_array($this->context->getMethod(), array('HEAD', 'GET'), true)) {
// no-op
} elseif ($allowSchemes) {
redirect_scheme:
$scheme = $this->context->getScheme();
$this->context->setScheme(key($allowSchemes));
try {
if ($ret = $this->doMatch($pathinfo)) {
return $this->redirect($pathinfo, $ret['_route'], $this->context->getScheme()) + $ret;
}
} finally {
$this->context->setScheme($scheme);
}
} elseif ('/' !== $pathinfo) {
$pathinfo = '/' !== $pathinfo[-1] ? $pathinfo.'/' : substr($pathinfo, 0, -1);
if ($ret = $this->doMatch($pathinfo, $allow, $allowSchemes)) {
return $this->redirect($pathinfo, $ret['_route']) + $ret;
}
if ($allowSchemes) {
goto redirect_scheme;
}
}
throw new ResourceNotFoundException();
}
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): ?array
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo);
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
if ('HEAD' === $requestMethod) {
$canonicalMethod = 'GET';
}
$matchedPathinfo = $pathinfo;
$regexList = array(
$this->regexpList = array(
0 => '{^(?'
.'|/(en|fr)/(?'
.'|admin/post/(?'
.'|(*:33)'
.'|new(*:43)'
.'|(\\d+)(*:55)'
.'|(\\d+)/edit(*:72)'
.'|(\\d+)/delete(*:91)'
.')'
.'|blog/(?'
.'|(*:107)'
.'|rss\\.xml(*:123)'
.'|p(?'
.'|age/([^/]++)(*:147)'
.'|osts/([^/]++)(*:168)'
.'|admin/post(?'
.'|(*:32)'
.'|/(?'
.'|new(*:46)'
.'|(\\d+)(*:58)'
.'|(\\d+)/edit(*:75)'
.'|(\\d+)/delete(*:94)'
.')'
.')'
.'|blog(?'
.'|(*:110)'
.'|/(?'
.'|rss\\.xml(*:130)'
.'|p(?'
.'|age/([^/]++)(*:154)'
.'|osts/([^/]++)(*:175)'
.')'
.'|comments/(\\d+)/new(*:202)'
.'|search(*:216)'
.')'
.'|comments/(\\d+)/new(*:195)'
.'|search(*:209)'
.')'
.'|log(?'
.'|in(*:226)'
.'|out(*:237)'
.'|in(*:234)'
.'|out(*:245)'
.')'
.')'
.'|/(en|fr)?(*:256)'
.')$}sD',
.'|/(en|fr)?(*:264)'
.')(?:/?)$}sD',
);
$this->dynamicRoutes = array(
32 => array(array(array('_route' => 'a', '_locale' => 'en'), array('_locale'), null, null, true, null)),
46 => array(array(array('_route' => 'b', '_locale' => 'en'), array('_locale'), null, null, false, null)),
58 => array(array(array('_route' => 'c', '_locale' => 'en'), array('_locale', 'id'), null, null, false, null)),
75 => array(array(array('_route' => 'd', '_locale' => 'en'), array('_locale', 'id'), null, null, false, null)),
94 => array(array(array('_route' => 'e', '_locale' => 'en'), array('_locale', 'id'), null, null, false, null)),
110 => array(array(array('_route' => 'f', '_locale' => 'en'), array('_locale'), null, null, true, null)),
130 => array(array(array('_route' => 'g', '_locale' => 'en'), array('_locale'), null, null, false, null)),
154 => array(array(array('_route' => 'h', '_locale' => 'en'), array('_locale', 'page'), null, null, false, null)),
175 => array(array(array('_route' => 'i', '_locale' => 'en'), array('_locale', 'page'), null, null, false, null)),
202 => array(array(array('_route' => 'j', '_locale' => 'en'), array('_locale', 'id'), null, null, false, null)),
216 => array(array(array('_route' => 'k', '_locale' => 'en'), array('_locale'), null, null, false, null)),
234 => array(array(array('_route' => 'l', '_locale' => 'en'), array('_locale'), null, null, false, null)),
245 => array(array(array('_route' => 'm', '_locale' => 'en'), array('_locale'), null, null, false, null)),
264 => array(array(array('_route' => 'n', '_locale' => 'en'), array('_locale'), null, null, false, null)),
);
foreach ($regexList as $offset => $regex) {
while (preg_match($regex, $matchedPathinfo, $matches)) {
switch ($m = (int) $matches['MARK']) {
default:
$routes = array(
33 => array(array('_route' => 'a', '_locale' => 'en'), array('_locale'), null, null),
43 => array(array('_route' => 'b', '_locale' => 'en'), array('_locale'), null, null),
55 => array(array('_route' => 'c', '_locale' => 'en'), array('_locale', 'id'), null, null),
72 => array(array('_route' => 'd', '_locale' => 'en'), array('_locale', 'id'), null, null),
91 => array(array('_route' => 'e', '_locale' => 'en'), array('_locale', 'id'), null, null),
107 => array(array('_route' => 'f', '_locale' => 'en'), array('_locale'), null, null),
123 => array(array('_route' => 'g', '_locale' => 'en'), array('_locale'), null, null),
147 => array(array('_route' => 'h', '_locale' => 'en'), array('_locale', 'page'), null, null),
168 => array(array('_route' => 'i', '_locale' => 'en'), array('_locale', 'page'), null, null),
195 => array(array('_route' => 'j', '_locale' => 'en'), array('_locale', 'id'), null, null),
209 => array(array('_route' => 'k', '_locale' => 'en'), array('_locale'), null, null),
226 => array(array('_route' => 'l', '_locale' => 'en'), array('_locale'), null, null),
237 => array(array('_route' => 'm', '_locale' => 'en'), array('_locale'), null, null),
256 => array(array('_route' => 'n', '_locale' => 'en'), array('_locale'), null, null),
);
list($ret, $vars, $requiredMethods, $requiredSchemes) = $routes[$m];
foreach ($vars as $i => $v) {
if (isset($matches[1 + $i])) {
$ret[$v] = $matches[1 + $i];
}
}
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
if ($hasRequiredScheme) {
$allow += $requiredMethods;
}
break;
}
if (!$hasRequiredScheme) {
$allowSchemes += $requiredSchemes;
break;
}
return $ret;
}
if (256 === $m) {
break;
}
$regex = substr_replace($regex, 'F', $m - $offset, 1 + strlen($m));
$offset += strlen($m);
}
}
if ('/' === $pathinfo && !$allow && !$allowSchemes) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}
return null;
}
}

View File

@@ -1,7 +1,6 @@
<?php
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherTrait;
use Symfony\Component\Routing\RequestContext;
/**
@@ -10,24 +9,12 @@ use Symfony\Component\Routing\RequestContext;
*/
class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
{
use PhpMatcherTrait;
public function __construct(RequestContext $context)
{
$this->context = $context;
}
public function match($rawPathinfo)
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo);
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
if ('HEAD' === $requestMethod) {
$canonicalMethod = 'GET';
}
$matchedPathinfo = $pathinfo;
$regexList = array(
$this->regexpList = array(
0 => '{^(?'
.'|/abc([^/]++)/(?'
.'|1(?'
@@ -45,56 +32,15 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
.')'
.')'
.')'
.')$}sD',
.')(?:/?)$}sD',
);
$this->dynamicRoutes = array(
27 => array(array(array('_route' => 'r1'), array('foo'), null, null, false, null)),
38 => array(array(array('_route' => 'r10'), array('foo'), null, null, false, null)),
46 => array(array(array('_route' => 'r100'), array('foo'), null, null, false, null)),
59 => array(array(array('_route' => 'r2'), array('foo'), null, null, false, null)),
70 => array(array(array('_route' => 'r20'), array('foo'), null, null, false, null)),
78 => array(array(array('_route' => 'r200'), array('foo'), null, null, false, null)),
);
foreach ($regexList as $offset => $regex) {
while (preg_match($regex, $matchedPathinfo, $matches)) {
switch ($m = (int) $matches['MARK']) {
default:
$routes = array(
27 => array(array('_route' => 'r1'), array('foo'), null, null),
38 => array(array('_route' => 'r10'), array('foo'), null, null),
46 => array(array('_route' => 'r100'), array('foo'), null, null),
59 => array(array('_route' => 'r2'), array('foo'), null, null),
70 => array(array('_route' => 'r20'), array('foo'), null, null),
78 => array(array('_route' => 'r200'), array('foo'), null, null),
);
list($ret, $vars, $requiredMethods, $requiredSchemes) = $routes[$m];
foreach ($vars as $i => $v) {
if (isset($matches[1 + $i])) {
$ret[$v] = $matches[1 + $i];
}
}
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
if ($hasRequiredScheme) {
$allow += $requiredMethods;
}
break;
}
if (!$hasRequiredScheme) {
$allowSchemes += $requiredSchemes;
break;
}
return $ret;
}
if (78 === $m) {
break;
}
$regex = substr_replace($regex, 'F', $m - $offset, 1 + strlen($m));
$offset += strlen($m);
}
}
if ('/' === $pathinfo && !$allow && !$allowSchemes) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}
throw $allow ? new MethodNotAllowedException(array_keys($allow)) : new ResourceNotFoundException();
}
}

View File

@@ -1,7 +1,6 @@
<?php
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherTrait;
use Symfony\Component\Routing\RequestContext;
/**
@@ -10,60 +9,26 @@ use Symfony\Component\Routing\RequestContext;
*/
class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
{
use PhpMatcherTrait;
public function __construct(RequestContext $context)
{
$this->context = $context;
}
public function match($rawPathinfo)
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo);
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
$host = strtolower($context->getHost());
if ('HEAD' === $requestMethod) {
$canonicalMethod = 'GET';
}
$matchedPathinfo = $host.'.'.$pathinfo;
$regexList = array(
$this->matchHost = true;
$this->regexpList = array(
0 => '{^(?'
.'|(?i:([^\\.]++)\\.exampple\\.com)\\.(?'
.'|/abc([^/]++)(?'
.'|(*:56)'
.')'
.')'
.')$}sD',
.')(?:/?)$}sD',
);
$this->dynamicRoutes = array(
56 => array(
array(array('_route' => 'r1'), array('foo', 'foo'), null, null, false, null),
array(array('_route' => 'r2'), array('foo', 'foo'), null, null, false, null),
),
);
foreach ($regexList as $offset => $regex) {
while (preg_match($regex, $matchedPathinfo, $matches)) {
switch ($m = (int) $matches['MARK']) {
case 56:
$matches = array('foo' => $matches[1] ?? null, 'foo' => $matches[2] ?? null);
// r1
return $this->mergeDefaults(array('_route' => 'r1') + $matches, array());
// r2
return $this->mergeDefaults(array('_route' => 'r2') + $matches, array());
break;
}
if (56 === $m) {
break;
}
$regex = substr_replace($regex, 'F', $m - $offset, 1 + strlen($m));
$offset += strlen($m);
}
}
if ('/' === $pathinfo && !$allow && !$allowSchemes) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}
throw $allow ? new MethodNotAllowedException(array_keys($allow)) : new ResourceNotFoundException();
}
}

View File

@@ -1,7 +1,6 @@
<?php
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherTrait;
use Symfony\Component\Routing\RequestContext;
/**
@@ -10,114 +9,34 @@ use Symfony\Component\Routing\RequestContext;
*/
class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\RedirectableUrlMatcher
{
use PhpMatcherTrait;
public function __construct(RequestContext $context)
{
$this->context = $context;
}
public function match($pathinfo)
{
$allow = $allowSchemes = array();
if ($ret = $this->doMatch($pathinfo, $allow, $allowSchemes)) {
return $ret;
}
if ($allow) {
throw new MethodNotAllowedException(array_keys($allow));
}
if (!in_array($this->context->getMethod(), array('HEAD', 'GET'), true)) {
// no-op
} elseif ($allowSchemes) {
redirect_scheme:
$scheme = $this->context->getScheme();
$this->context->setScheme(key($allowSchemes));
try {
if ($ret = $this->doMatch($pathinfo)) {
return $this->redirect($pathinfo, $ret['_route'], $this->context->getScheme()) + $ret;
}
} finally {
$this->context->setScheme($scheme);
}
} elseif ('/' !== $pathinfo) {
$pathinfo = '/' !== $pathinfo[-1] ? $pathinfo.'/' : substr($pathinfo, 0, -1);
if ($ret = $this->doMatch($pathinfo, $allow, $allowSchemes)) {
return $this->redirect($pathinfo, $ret['_route']) + $ret;
}
if ($allowSchemes) {
goto redirect_scheme;
}
}
throw new ResourceNotFoundException();
}
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): ?array
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo);
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
$host = strtolower($context->getHost());
if ('HEAD' === $requestMethod) {
$canonicalMethod = 'GET';
}
switch ($pathinfo) {
default:
$routes = array(
'/test/baz' => array(array('_route' => 'baz'), null, null, null),
'/test/baz.html' => array(array('_route' => 'baz2'), null, null, null),
'/test/baz3/' => array(array('_route' => 'baz3'), null, null, null),
'/foofoo' => array(array('_route' => 'foofoo', 'def' => 'test'), null, null, null),
'/spa ce' => array(array('_route' => 'space'), null, null, null),
'/multi/new' => array(array('_route' => 'overridden2'), null, null, null),
'/multi/hey/' => array(array('_route' => 'hey'), null, null, null),
'/ababa' => array(array('_route' => 'ababa'), null, null, null),
'/route1' => array(array('_route' => 'route1'), 'a.example.com', null, null),
'/c2/route2' => array(array('_route' => 'route2'), 'a.example.com', null, null),
'/route4' => array(array('_route' => 'route4'), 'a.example.com', null, null),
'/c2/route3' => array(array('_route' => 'route3'), 'b.example.com', null, null),
'/route5' => array(array('_route' => 'route5'), 'c.example.com', null, null),
'/route6' => array(array('_route' => 'route6'), null, null, null),
'/route11' => array(array('_route' => 'route11'), '#^(?P<var1>[^\\.]++)\\.example\\.com$#sDi', null, null),
'/route12' => array(array('_route' => 'route12', 'var1' => 'val'), '#^(?P<var1>[^\\.]++)\\.example\\.com$#sDi', null, null),
'/route17' => array(array('_route' => 'route17'), null, null, null),
'/secure' => array(array('_route' => 'secure'), null, null, array('https' => 0)),
'/nonsecure' => array(array('_route' => 'nonsecure'), null, null, array('http' => 0)),
);
if (!isset($routes[$pathinfo])) {
break;
}
list($ret, $requiredHost, $requiredMethods, $requiredSchemes) = $routes[$pathinfo];
if ($requiredHost) {
if ('#' !== $requiredHost[0] ? $requiredHost !== $host : !preg_match($requiredHost, $host, $hostMatches)) {
break;
}
if ('#' === $requiredHost[0] && $hostMatches) {
$hostMatches['_route'] = $ret['_route'];
$ret = $this->mergeDefaults($hostMatches, $ret);
}
}
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
if ($hasRequiredScheme) {
$allow += $requiredMethods;
}
break;
}
if (!$hasRequiredScheme) {
$allowSchemes += $requiredSchemes;
break;
}
return $ret;
}
$matchedPathinfo = $host.'.'.$pathinfo;
$regexList = array(
$this->matchHost = true;
$this->staticRoutes = array(
'/test/baz' => array(array(array('_route' => 'baz'), null, null, null, false, null)),
'/test/baz.html' => array(array(array('_route' => 'baz2'), null, null, null, false, null)),
'/test/baz3' => array(array(array('_route' => 'baz3'), null, null, null, true, null)),
'/foofoo' => array(array(array('_route' => 'foofoo', 'def' => 'test'), null, null, null, false, null)),
'/spa ce' => array(array(array('_route' => 'space'), null, null, null, false, null)),
'/multi/new' => array(array(array('_route' => 'overridden2'), null, null, null, false, null)),
'/multi/hey' => array(array(array('_route' => 'hey'), null, null, null, true, null)),
'/ababa' => array(array(array('_route' => 'ababa'), null, null, null, false, null)),
'/route1' => array(array(array('_route' => 'route1'), 'a.example.com', null, null, false, null)),
'/c2/route2' => array(array(array('_route' => 'route2'), 'a.example.com', null, null, false, null)),
'/route4' => array(array(array('_route' => 'route4'), 'a.example.com', null, null, false, null)),
'/c2/route3' => array(array(array('_route' => 'route3'), 'b.example.com', null, null, false, null)),
'/route5' => array(array(array('_route' => 'route5'), 'c.example.com', null, null, false, null)),
'/route6' => array(array(array('_route' => 'route6'), null, null, null, false, null)),
'/route11' => array(array(array('_route' => 'route11'), '#^(?P<var1>[^\\.]++)\\.example\\.com$#sDi', null, null, false, null)),
'/route12' => array(array(array('_route' => 'route12', 'var1' => 'val'), '#^(?P<var1>[^\\.]++)\\.example\\.com$#sDi', null, null, false, null)),
'/route17' => array(array(array('_route' => 'route17'), null, null, null, false, null)),
'/secure' => array(array(array('_route' => 'secure'), null, null, array('https' => 0), false, null)),
'/nonsecure' => array(array(array('_route' => 'nonsecure'), null, null, array('http' => 0), false, null)),
);
$this->regexpList = array(
0 => '{^(?'
.'|(?:(?:[^./]*+\\.)++)(?'
.'|/foo/(baz|symfony)(*:47)'
@@ -125,160 +44,72 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
.'|/([^/]++)(*:70)'
.'|head/([^/]++)(*:90)'
.')'
.'|/test/([^/]++)/(?'
.'|(*:116)'
.'|/test/([^/]++)(?'
.'|(*:115)'
.')'
.'|/([\']+)(*:132)'
.'|/([\']+)(*:131)'
.'|/a/(?'
.'|b\'b/([^/]++)(?'
.'|(*:161)'
.'|(*:169)'
.'|(*:160)'
.'|(*:168)'
.')'
.'|(.*)(*:182)'
.'|(.*)(*:181)'
.'|b\'b/([^/]++)(?'
.'|(*:205)'
.'|(*:213)'
.'|(*:204)'
.'|(*:212)'
.')'
.')'
.'|/multi/hello(?:/([^/]++))?(*:249)'
.'|/multi/hello(?:/([^/]++))?(*:248)'
.'|/([^/]++)/b/([^/]++)(?'
.'|(*:280)'
.'|(*:288)'
.'|(*:279)'
.'|(*:287)'
.')'
.'|/aba/([^/]++)(*:310)'
.'|/aba/([^/]++)(*:309)'
.')|(?i:([^\\.]++)\\.example\\.com)\\.(?'
.'|/route1(?'
.'|3/([^/]++)(*:372)'
.'|4/([^/]++)(*:390)'
.'|3/([^/]++)(*:371)'
.'|4/([^/]++)(*:389)'
.')'
.')|(?i:c\\.example\\.com)\\.(?'
.'|/route15/([^/]++)(*:442)'
.'|/route15/([^/]++)(*:441)'
.')|(?:(?:[^./]*+\\.)++)(?'
.'|/route16/([^/]++)(*:490)'
.'|/route16/([^/]++)(*:489)'
.'|/a/(?'
.'|a\\.\\.\\.(*:511)'
.'|a\\.\\.\\.(*:510)'
.'|b/(?'
.'|([^/]++)(*:532)'
.'|c/([^/]++)(*:550)'
.'|([^/]++)(*:531)'
.'|c/([^/]++)(*:549)'
.')'
.')'
.')'
.')$}sD',
.')(?:/?)$}sD',
);
$this->dynamicRoutes = array(
47 => array(array(array('_route' => 'foo', 'def' => 'test'), array('bar'), null, null, false, null)),
70 => array(array(array('_route' => 'bar'), array('foo'), array('GET' => 0, 'HEAD' => 1), null, false, null)),
90 => array(array(array('_route' => 'barhead'), array('foo'), array('GET' => 0), null, false, null)),
115 => array(
array(array('_route' => 'baz4'), array('foo'), null, null, true, null),
array(array('_route' => 'baz5'), array('foo'), array('POST' => 0), null, true, null),
array(array('_route' => 'baz.baz6'), array('foo'), array('PUT' => 0), null, true, null),
),
131 => array(array(array('_route' => 'quoter'), array('quoter'), null, null, false, null)),
160 => array(array(array('_route' => 'foo1'), array('foo'), array('PUT' => 0), null, false, null)),
168 => array(array(array('_route' => 'bar1'), array('bar'), null, null, false, null)),
181 => array(array(array('_route' => 'overridden'), array('var'), null, null, false, null)),
204 => array(array(array('_route' => 'foo2'), array('foo1'), null, null, false, null)),
212 => array(array(array('_route' => 'bar2'), array('bar1'), null, null, false, null)),
248 => array(array(array('_route' => 'helloWorld', 'who' => 'World!'), array('who'), null, null, false, null)),
279 => array(array(array('_route' => 'foo3'), array('_locale', 'foo'), null, null, false, null)),
287 => array(array(array('_route' => 'bar3'), array('_locale', 'bar'), null, null, false, null)),
309 => array(array(array('_route' => 'foo4'), array('foo'), null, null, false, null)),
371 => array(array(array('_route' => 'route13'), array('var1', 'name'), null, null, false, null)),
389 => array(array(array('_route' => 'route14', 'var1' => 'val'), array('var1', 'name'), null, null, false, null)),
441 => array(array(array('_route' => 'route15'), array('name'), null, null, false, null)),
489 => array(array(array('_route' => 'route16', 'var1' => 'val'), array('name'), null, null, false, null)),
510 => array(array(array('_route' => 'a'), array(), null, null, false, null)),
531 => array(array(array('_route' => 'b'), array('var'), null, null, false, null)),
549 => array(array(array('_route' => 'c'), array('var'), null, null, false, null)),
);
foreach ($regexList as $offset => $regex) {
while (preg_match($regex, $matchedPathinfo, $matches)) {
switch ($m = (int) $matches['MARK']) {
case 116:
$matches = array('foo' => $matches[1] ?? null);
// baz4
return $this->mergeDefaults(array('_route' => 'baz4') + $matches, array());
// baz5
$ret = $this->mergeDefaults(array('_route' => 'baz5') + $matches, array());
if (!isset(($a = array('POST' => 0))[$requestMethod])) {
$allow += $a;
goto not_baz5;
}
return $ret;
not_baz5:
// baz.baz6
$ret = $this->mergeDefaults(array('_route' => 'baz.baz6') + $matches, array());
if (!isset(($a = array('PUT' => 0))[$requestMethod])) {
$allow += $a;
goto not_bazbaz6;
}
return $ret;
not_bazbaz6:
break;
case 161:
$matches = array('foo' => $matches[1] ?? null);
// foo1
$ret = $this->mergeDefaults(array('_route' => 'foo1') + $matches, array());
if (!isset(($a = array('PUT' => 0))[$requestMethod])) {
$allow += $a;
goto not_foo1;
}
return $ret;
not_foo1:
break;
case 205:
$matches = array('foo1' => $matches[1] ?? null);
// foo2
return $this->mergeDefaults(array('_route' => 'foo2') + $matches, array());
break;
case 280:
$matches = array('_locale' => $matches[1] ?? null, 'foo' => $matches[2] ?? null);
// foo3
return $this->mergeDefaults(array('_route' => 'foo3') + $matches, array());
break;
default:
$routes = array(
47 => array(array('_route' => 'foo', 'def' => 'test'), array('bar'), null, null),
70 => array(array('_route' => 'bar'), array('foo'), array('GET' => 0, 'HEAD' => 1), null),
90 => array(array('_route' => 'barhead'), array('foo'), array('GET' => 0), null),
132 => array(array('_route' => 'quoter'), array('quoter'), null, null),
169 => array(array('_route' => 'bar1'), array('bar'), null, null),
182 => array(array('_route' => 'overridden'), array('var'), null, null),
213 => array(array('_route' => 'bar2'), array('bar1'), null, null),
249 => array(array('_route' => 'helloWorld', 'who' => 'World!'), array('who'), null, null),
288 => array(array('_route' => 'bar3'), array('_locale', 'bar'), null, null),
310 => array(array('_route' => 'foo4'), array('foo'), null, null),
372 => array(array('_route' => 'route13'), array('var1', 'name'), null, null),
390 => array(array('_route' => 'route14', 'var1' => 'val'), array('var1', 'name'), null, null),
442 => array(array('_route' => 'route15'), array('name'), null, null),
490 => array(array('_route' => 'route16', 'var1' => 'val'), array('name'), null, null),
511 => array(array('_route' => 'a'), array(), null, null),
532 => array(array('_route' => 'b'), array('var'), null, null),
550 => array(array('_route' => 'c'), array('var'), null, null),
);
list($ret, $vars, $requiredMethods, $requiredSchemes) = $routes[$m];
foreach ($vars as $i => $v) {
if (isset($matches[1 + $i])) {
$ret[$v] = $matches[1 + $i];
}
}
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
if ($hasRequiredScheme) {
$allow += $requiredMethods;
}
break;
}
if (!$hasRequiredScheme) {
$allowSchemes += $requiredSchemes;
break;
}
return $ret;
}
if (550 === $m) {
break;
}
$regex = substr_replace($regex, 'F', $m - $offset, 1 + strlen($m));
$offset += strlen($m);
}
}
if ('/' === $pathinfo && !$allow && !$allowSchemes) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}
return null;
}
}

View File

@@ -1,7 +1,6 @@
<?php
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherTrait;
use Symfony\Component\Routing\RequestContext;
/**
@@ -10,103 +9,27 @@ use Symfony\Component\Routing\RequestContext;
*/
class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
{
use PhpMatcherTrait;
public function __construct(RequestContext $context)
{
$this->context = $context;
}
public function match($rawPathinfo)
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo);
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
if ('HEAD' === $requestMethod) {
$canonicalMethod = 'GET';
}
switch ($pathinfo) {
case '/with-condition':
// with-condition
if (($context->getMethod() == "GET")) {
return array('_route' => 'with-condition');
}
break;
default:
$routes = array(
'/rootprefix/test' => array(array('_route' => 'static'), null, null, null),
);
if (!isset($routes[$pathinfo])) {
break;
}
list($ret, $requiredHost, $requiredMethods, $requiredSchemes) = $routes[$pathinfo];
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
if ($hasRequiredScheme) {
$allow += $requiredMethods;
}
break;
}
if (!$hasRequiredScheme) {
$allowSchemes += $requiredSchemes;
break;
}
return $ret;
}
$matchedPathinfo = $pathinfo;
$regexList = array(
$this->staticRoutes = array(
'/rootprefix/test' => array(array(array('_route' => 'static'), null, null, null, false, null)),
'/with-condition' => array(array(array('_route' => 'with-condition'), null, null, null, false, -1)),
);
$this->regexpList = array(
0 => '{^(?'
.'|/rootprefix/([^/]++)(*:27)'
.')$}sD',
.')(?:/?)$}sD',
);
foreach ($regexList as $offset => $regex) {
while (preg_match($regex, $matchedPathinfo, $matches)) {
switch ($m = (int) $matches['MARK']) {
default:
$routes = array(
27 => array(array('_route' => 'dynamic'), array('var'), null, null),
);
list($ret, $vars, $requiredMethods, $requiredSchemes) = $routes[$m];
foreach ($vars as $i => $v) {
if (isset($matches[1 + $i])) {
$ret[$v] = $matches[1 + $i];
}
}
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
if ($hasRequiredScheme) {
$allow += $requiredMethods;
}
break;
}
if (!$hasRequiredScheme) {
$allowSchemes += $requiredSchemes;
break;
}
return $ret;
}
if (27 === $m) {
break;
}
$regex = substr_replace($regex, 'F', $m - $offset, 1 + strlen($m));
$offset += strlen($m);
$this->dynamicRoutes = array(
27 => array(array(array('_route' => 'dynamic'), array('var'), null, null, false, null)),
);
$this->checkCondition = static function ($condition, $context, $request) {
switch ($condition) {
case -1: return ($context->getMethod() == "GET");
}
}
if ('/' === $pathinfo && !$allow && !$allowSchemes) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}
throw $allow ? new MethodNotAllowedException(array_keys($allow)) : new ResourceNotFoundException();
};
}
}

View File

@@ -1,7 +1,6 @@
<?php
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherTrait;
use Symfony\Component\Routing\RequestContext;
/**
@@ -10,75 +9,20 @@ use Symfony\Component\Routing\RequestContext;
*/
class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
{
use PhpMatcherTrait;
public function __construct(RequestContext $context)
{
$this->context = $context;
}
public function match($rawPathinfo)
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo);
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
if ('HEAD' === $requestMethod) {
$canonicalMethod = 'GET';
}
switch ($pathinfo) {
case '/put_and_post':
// put_and_post
$ret = array('_route' => 'put_and_post');
if (!isset(($a = array('PUT' => 0, 'POST' => 1))[$requestMethod])) {
$allow += $a;
goto not_put_and_post;
}
return $ret;
not_put_and_post:
// put_and_get_and_head
$ret = array('_route' => 'put_and_get_and_head');
if (!isset(($a = array('PUT' => 0, 'GET' => 1, 'HEAD' => 2))[$canonicalMethod])) {
$allow += $a;
goto not_put_and_get_and_head;
}
return $ret;
not_put_and_get_and_head:
break;
default:
$routes = array(
'/just_head' => array(array('_route' => 'just_head'), null, array('HEAD' => 0), null),
'/head_and_get' => array(array('_route' => 'head_and_get'), null, array('HEAD' => 0, 'GET' => 1), null),
'/get_and_head' => array(array('_route' => 'get_and_head'), null, array('GET' => 0, 'HEAD' => 1), null),
'/post_and_head' => array(array('_route' => 'post_and_head'), null, array('POST' => 0, 'HEAD' => 1), null),
);
if (!isset($routes[$pathinfo])) {
break;
}
list($ret, $requiredHost, $requiredMethods, $requiredSchemes) = $routes[$pathinfo];
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
if ($hasRequiredScheme) {
$allow += $requiredMethods;
}
break;
}
if (!$hasRequiredScheme) {
$allowSchemes += $requiredSchemes;
break;
}
return $ret;
}
if ('/' === $pathinfo && !$allow && !$allowSchemes) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}
throw $allow ? new MethodNotAllowedException(array_keys($allow)) : new ResourceNotFoundException();
$this->staticRoutes = array(
'/just_head' => array(array(array('_route' => 'just_head'), null, array('HEAD' => 0), null, false, null)),
'/head_and_get' => array(array(array('_route' => 'head_and_get'), null, array('HEAD' => 0, 'GET' => 1), null, false, null)),
'/get_and_head' => array(array(array('_route' => 'get_and_head'), null, array('GET' => 0, 'HEAD' => 1), null, false, null)),
'/post_and_head' => array(array(array('_route' => 'post_and_head'), null, array('POST' => 0, 'HEAD' => 1), null, false, null)),
'/put_and_post' => array(
array(array('_route' => 'put_and_post'), null, array('PUT' => 0, 'POST' => 1), null, false, null),
array(array('_route' => 'put_and_get_and_head'), null, array('PUT' => 0, 'GET' => 1, 'HEAD' => 2), null, false, null),
),
);
}
}

View File

@@ -1,7 +1,6 @@
<?php
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherTrait;
use Symfony\Component\Routing\RequestContext;
/**
@@ -10,145 +9,34 @@ use Symfony\Component\Routing\RequestContext;
*/
class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\RedirectableUrlMatcher
{
use PhpMatcherTrait;
public function __construct(RequestContext $context)
{
$this->context = $context;
}
public function match($pathinfo)
{
$allow = $allowSchemes = array();
if ($ret = $this->doMatch($pathinfo, $allow, $allowSchemes)) {
return $ret;
}
if ($allow) {
throw new MethodNotAllowedException(array_keys($allow));
}
if (!in_array($this->context->getMethod(), array('HEAD', 'GET'), true)) {
// no-op
} elseif ($allowSchemes) {
redirect_scheme:
$scheme = $this->context->getScheme();
$this->context->setScheme(key($allowSchemes));
try {
if ($ret = $this->doMatch($pathinfo)) {
return $this->redirect($pathinfo, $ret['_route'], $this->context->getScheme()) + $ret;
}
} finally {
$this->context->setScheme($scheme);
}
} elseif ('/' !== $pathinfo) {
$pathinfo = '/' !== $pathinfo[-1] ? $pathinfo.'/' : substr($pathinfo, 0, -1);
if ($ret = $this->doMatch($pathinfo, $allow, $allowSchemes)) {
return $this->redirect($pathinfo, $ret['_route']) + $ret;
}
if ($allowSchemes) {
goto redirect_scheme;
}
}
throw new ResourceNotFoundException();
}
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): ?array
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo);
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
if ('HEAD' === $requestMethod) {
$canonicalMethod = 'GET';
}
switch ($pathinfo) {
default:
$routes = array(
'/a/11' => array(array('_route' => 'a_first'), null, null, null),
'/a/22' => array(array('_route' => 'a_second'), null, null, null),
'/a/333' => array(array('_route' => 'a_third'), null, null, null),
'/a/44/' => array(array('_route' => 'a_fourth'), null, null, null),
'/a/55/' => array(array('_route' => 'a_fifth'), null, null, null),
'/a/66/' => array(array('_route' => 'a_sixth'), null, null, null),
'/nested/group/a/' => array(array('_route' => 'nested_a'), null, null, null),
'/nested/group/b/' => array(array('_route' => 'nested_b'), null, null, null),
'/nested/group/c/' => array(array('_route' => 'nested_c'), null, null, null),
'/slashed/group/' => array(array('_route' => 'slashed_a'), null, null, null),
'/slashed/group/b/' => array(array('_route' => 'slashed_b'), null, null, null),
'/slashed/group/c/' => array(array('_route' => 'slashed_c'), null, null, null),
);
if (!isset($routes[$pathinfo])) {
break;
}
list($ret, $requiredHost, $requiredMethods, $requiredSchemes) = $routes[$pathinfo];
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
if ($hasRequiredScheme) {
$allow += $requiredMethods;
}
break;
}
if (!$hasRequiredScheme) {
$allowSchemes += $requiredSchemes;
break;
}
return $ret;
}
$matchedPathinfo = $pathinfo;
$regexList = array(
$this->staticRoutes = array(
'/a/11' => array(array(array('_route' => 'a_first'), null, null, null, false, null)),
'/a/22' => array(array(array('_route' => 'a_second'), null, null, null, false, null)),
'/a/333' => array(array(array('_route' => 'a_third'), null, null, null, false, null)),
'/a/44' => array(array(array('_route' => 'a_fourth'), null, null, null, true, null)),
'/a/55' => array(array(array('_route' => 'a_fifth'), null, null, null, true, null)),
'/a/66' => array(array(array('_route' => 'a_sixth'), null, null, null, true, null)),
'/nested/group/a' => array(array(array('_route' => 'nested_a'), null, null, null, true, null)),
'/nested/group/b' => array(array(array('_route' => 'nested_b'), null, null, null, true, null)),
'/nested/group/c' => array(array(array('_route' => 'nested_c'), null, null, null, true, null)),
'/slashed/group' => array(array(array('_route' => 'slashed_a'), null, null, null, true, null)),
'/slashed/group/b' => array(array(array('_route' => 'slashed_b'), null, null, null, true, null)),
'/slashed/group/c' => array(array(array('_route' => 'slashed_c'), null, null, null, true, null)),
);
$this->regexpList = array(
0 => '{^(?'
.'|/([^/]++)(*:16)'
.'|/nested/([^/]++)(*:39)'
.')$}sD',
.')(?:/?)$}sD',
);
$this->dynamicRoutes = array(
16 => array(array(array('_route' => 'a_wildcard'), array('param'), null, null, false, null)),
39 => array(array(array('_route' => 'nested_wildcard'), array('param'), null, null, false, null)),
);
foreach ($regexList as $offset => $regex) {
while (preg_match($regex, $matchedPathinfo, $matches)) {
switch ($m = (int) $matches['MARK']) {
default:
$routes = array(
16 => array(array('_route' => 'a_wildcard'), array('param'), null, null),
39 => array(array('_route' => 'nested_wildcard'), array('param'), null, null),
);
list($ret, $vars, $requiredMethods, $requiredSchemes) = $routes[$m];
foreach ($vars as $i => $v) {
if (isset($matches[1 + $i])) {
$ret[$v] = $matches[1 + $i];
}
}
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
if ($hasRequiredScheme) {
$allow += $requiredMethods;
}
break;
}
if (!$hasRequiredScheme) {
$allowSchemes += $requiredSchemes;
break;
}
return $ret;
}
if (39 === $m) {
break;
}
$regex = substr_replace($regex, 'F', $m - $offset, 1 + strlen($m));
$offset += strlen($m);
}
}
if ('/' === $pathinfo && !$allow && !$allowSchemes) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}
return null;
}
}

View File

@@ -1,7 +1,6 @@
<?php
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherTrait;
use Symfony\Component\Routing\RequestContext;
/**
@@ -10,122 +9,46 @@ use Symfony\Component\Routing\RequestContext;
*/
class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
{
use PhpMatcherTrait;
public function __construct(RequestContext $context)
{
$this->context = $context;
}
public function match($rawPathinfo)
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo);
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
if ('HEAD' === $requestMethod) {
$canonicalMethod = 'GET';
}
switch ($pathinfo) {
default:
$routes = array(
'/trailing/simple/no-methods/' => array(array('_route' => 'simple_trailing_slash_no_methods'), null, null, null),
'/trailing/simple/get-method/' => array(array('_route' => 'simple_trailing_slash_GET_method'), null, array('GET' => 0), null),
'/trailing/simple/head-method/' => array(array('_route' => 'simple_trailing_slash_HEAD_method'), null, array('HEAD' => 0), null),
'/trailing/simple/post-method/' => array(array('_route' => 'simple_trailing_slash_POST_method'), null, array('POST' => 0), null),
'/not-trailing/simple/no-methods' => array(array('_route' => 'simple_not_trailing_slash_no_methods'), null, null, null),
'/not-trailing/simple/get-method' => array(array('_route' => 'simple_not_trailing_slash_GET_method'), null, array('GET' => 0), null),
'/not-trailing/simple/head-method' => array(array('_route' => 'simple_not_trailing_slash_HEAD_method'), null, array('HEAD' => 0), null),
'/not-trailing/simple/post-method' => array(array('_route' => 'simple_not_trailing_slash_POST_method'), null, array('POST' => 0), null),
);
if (!isset($routes[$pathinfo])) {
break;
}
list($ret, $requiredHost, $requiredMethods, $requiredSchemes) = $routes[$pathinfo];
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
if ($hasRequiredScheme) {
$allow += $requiredMethods;
}
break;
}
if (!$hasRequiredScheme) {
$allowSchemes += $requiredSchemes;
break;
}
return $ret;
}
$matchedPathinfo = $pathinfo;
$regexList = array(
$this->staticRoutes = array(
'/trailing/simple/no-methods' => array(array(array('_route' => 'simple_trailing_slash_no_methods'), null, null, null, true, null)),
'/trailing/simple/get-method' => array(array(array('_route' => 'simple_trailing_slash_GET_method'), null, array('GET' => 0), null, true, null)),
'/trailing/simple/head-method' => array(array(array('_route' => 'simple_trailing_slash_HEAD_method'), null, array('HEAD' => 0), null, true, null)),
'/trailing/simple/post-method' => array(array(array('_route' => 'simple_trailing_slash_POST_method'), null, array('POST' => 0), null, true, null)),
'/not-trailing/simple/no-methods' => array(array(array('_route' => 'simple_not_trailing_slash_no_methods'), null, null, null, false, null)),
'/not-trailing/simple/get-method' => array(array(array('_route' => 'simple_not_trailing_slash_GET_method'), null, array('GET' => 0), null, false, null)),
'/not-trailing/simple/head-method' => array(array(array('_route' => 'simple_not_trailing_slash_HEAD_method'), null, array('HEAD' => 0), null, false, null)),
'/not-trailing/simple/post-method' => array(array(array('_route' => 'simple_not_trailing_slash_POST_method'), null, array('POST' => 0), null, false, null)),
);
$this->regexpList = array(
0 => '{^(?'
.'|/trailing/regex/(?'
.'|no\\-methods/([^/]++)/(*:47)'
.'|get\\-method/([^/]++)/(*:75)'
.'|head\\-method/([^/]++)/(*:104)'
.'|post\\-method/([^/]++)/(*:134)'
.'|no\\-methods/([^/]++)(*:46)'
.'|get\\-method/([^/]++)(*:73)'
.'|head\\-method/([^/]++)(*:101)'
.'|post\\-method/([^/]++)(*:130)'
.')'
.'|/not\\-trailing/regex/(?'
.'|no\\-methods/([^/]++)(*:187)'
.'|get\\-method/([^/]++)(*:215)'
.'|head\\-method/([^/]++)(*:244)'
.'|post\\-method/([^/]++)(*:273)'
.'|no\\-methods/([^/]++)(*:183)'
.'|get\\-method/([^/]++)(*:211)'
.'|head\\-method/([^/]++)(*:240)'
.'|post\\-method/([^/]++)(*:269)'
.')'
.')$}sD',
.')(?:/?)$}sD',
);
$this->dynamicRoutes = array(
46 => array(array(array('_route' => 'regex_trailing_slash_no_methods'), array('param'), null, null, true, null)),
73 => array(array(array('_route' => 'regex_trailing_slash_GET_method'), array('param'), array('GET' => 0), null, true, null)),
101 => array(array(array('_route' => 'regex_trailing_slash_HEAD_method'), array('param'), array('HEAD' => 0), null, true, null)),
130 => array(array(array('_route' => 'regex_trailing_slash_POST_method'), array('param'), array('POST' => 0), null, true, null)),
183 => array(array(array('_route' => 'regex_not_trailing_slash_no_methods'), array('param'), null, null, false, null)),
211 => array(array(array('_route' => 'regex_not_trailing_slash_GET_method'), array('param'), array('GET' => 0), null, false, null)),
240 => array(array(array('_route' => 'regex_not_trailing_slash_HEAD_method'), array('param'), array('HEAD' => 0), null, false, null)),
269 => array(array(array('_route' => 'regex_not_trailing_slash_POST_method'), array('param'), array('POST' => 0), null, false, null)),
);
foreach ($regexList as $offset => $regex) {
while (preg_match($regex, $matchedPathinfo, $matches)) {
switch ($m = (int) $matches['MARK']) {
default:
$routes = array(
47 => array(array('_route' => 'regex_trailing_slash_no_methods'), array('param'), null, null),
75 => array(array('_route' => 'regex_trailing_slash_GET_method'), array('param'), array('GET' => 0), null),
104 => array(array('_route' => 'regex_trailing_slash_HEAD_method'), array('param'), array('HEAD' => 0), null),
134 => array(array('_route' => 'regex_trailing_slash_POST_method'), array('param'), array('POST' => 0), null),
187 => array(array('_route' => 'regex_not_trailing_slash_no_methods'), array('param'), null, null),
215 => array(array('_route' => 'regex_not_trailing_slash_GET_method'), array('param'), array('GET' => 0), null),
244 => array(array('_route' => 'regex_not_trailing_slash_HEAD_method'), array('param'), array('HEAD' => 0), null),
273 => array(array('_route' => 'regex_not_trailing_slash_POST_method'), array('param'), array('POST' => 0), null),
);
list($ret, $vars, $requiredMethods, $requiredSchemes) = $routes[$m];
foreach ($vars as $i => $v) {
if (isset($matches[1 + $i])) {
$ret[$v] = $matches[1 + $i];
}
}
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
if ($hasRequiredScheme) {
$allow += $requiredMethods;
}
break;
}
if (!$hasRequiredScheme) {
$allowSchemes += $requiredSchemes;
break;
}
return $ret;
}
if (273 === $m) {
break;
}
$regex = substr_replace($regex, 'F', $m - $offset, 1 + strlen($m));
$offset += strlen($m);
}
}
if ('/' === $pathinfo && !$allow && !$allowSchemes) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}
throw $allow ? new MethodNotAllowedException(array_keys($allow)) : new ResourceNotFoundException();
}
}

View File

@@ -1,7 +1,6 @@
<?php
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherTrait;
use Symfony\Component\Routing\RequestContext;
/**
@@ -10,157 +9,46 @@ use Symfony\Component\Routing\RequestContext;
*/
class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\RedirectableUrlMatcher
{
use PhpMatcherTrait;
public function __construct(RequestContext $context)
{
$this->context = $context;
}
public function match($pathinfo)
{
$allow = $allowSchemes = array();
if ($ret = $this->doMatch($pathinfo, $allow, $allowSchemes)) {
return $ret;
}
if ($allow) {
throw new MethodNotAllowedException(array_keys($allow));
}
if (!in_array($this->context->getMethod(), array('HEAD', 'GET'), true)) {
// no-op
} elseif ($allowSchemes) {
redirect_scheme:
$scheme = $this->context->getScheme();
$this->context->setScheme(key($allowSchemes));
try {
if ($ret = $this->doMatch($pathinfo)) {
return $this->redirect($pathinfo, $ret['_route'], $this->context->getScheme()) + $ret;
}
} finally {
$this->context->setScheme($scheme);
}
} elseif ('/' !== $pathinfo) {
$pathinfo = '/' !== $pathinfo[-1] ? $pathinfo.'/' : substr($pathinfo, 0, -1);
if ($ret = $this->doMatch($pathinfo, $allow, $allowSchemes)) {
return $this->redirect($pathinfo, $ret['_route']) + $ret;
}
if ($allowSchemes) {
goto redirect_scheme;
}
}
throw new ResourceNotFoundException();
}
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): ?array
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo);
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
if ('HEAD' === $requestMethod) {
$canonicalMethod = 'GET';
}
switch ($pathinfo) {
default:
$routes = array(
'/trailing/simple/no-methods/' => array(array('_route' => 'simple_trailing_slash_no_methods'), null, null, null),
'/trailing/simple/get-method/' => array(array('_route' => 'simple_trailing_slash_GET_method'), null, array('GET' => 0), null),
'/trailing/simple/head-method/' => array(array('_route' => 'simple_trailing_slash_HEAD_method'), null, array('HEAD' => 0), null),
'/trailing/simple/post-method/' => array(array('_route' => 'simple_trailing_slash_POST_method'), null, array('POST' => 0), null),
'/not-trailing/simple/no-methods' => array(array('_route' => 'simple_not_trailing_slash_no_methods'), null, null, null),
'/not-trailing/simple/get-method' => array(array('_route' => 'simple_not_trailing_slash_GET_method'), null, array('GET' => 0), null),
'/not-trailing/simple/head-method' => array(array('_route' => 'simple_not_trailing_slash_HEAD_method'), null, array('HEAD' => 0), null),
'/not-trailing/simple/post-method' => array(array('_route' => 'simple_not_trailing_slash_POST_method'), null, array('POST' => 0), null),
);
if (!isset($routes[$pathinfo])) {
break;
}
list($ret, $requiredHost, $requiredMethods, $requiredSchemes) = $routes[$pathinfo];
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
if ($hasRequiredScheme) {
$allow += $requiredMethods;
}
break;
}
if (!$hasRequiredScheme) {
$allowSchemes += $requiredSchemes;
break;
}
return $ret;
}
$matchedPathinfo = $pathinfo;
$regexList = array(
$this->staticRoutes = array(
'/trailing/simple/no-methods' => array(array(array('_route' => 'simple_trailing_slash_no_methods'), null, null, null, true, null)),
'/trailing/simple/get-method' => array(array(array('_route' => 'simple_trailing_slash_GET_method'), null, array('GET' => 0), null, true, null)),
'/trailing/simple/head-method' => array(array(array('_route' => 'simple_trailing_slash_HEAD_method'), null, array('HEAD' => 0), null, true, null)),
'/trailing/simple/post-method' => array(array(array('_route' => 'simple_trailing_slash_POST_method'), null, array('POST' => 0), null, true, null)),
'/not-trailing/simple/no-methods' => array(array(array('_route' => 'simple_not_trailing_slash_no_methods'), null, null, null, false, null)),
'/not-trailing/simple/get-method' => array(array(array('_route' => 'simple_not_trailing_slash_GET_method'), null, array('GET' => 0), null, false, null)),
'/not-trailing/simple/head-method' => array(array(array('_route' => 'simple_not_trailing_slash_HEAD_method'), null, array('HEAD' => 0), null, false, null)),
'/not-trailing/simple/post-method' => array(array(array('_route' => 'simple_not_trailing_slash_POST_method'), null, array('POST' => 0), null, false, null)),
);
$this->regexpList = array(
0 => '{^(?'
.'|/trailing/regex/(?'
.'|no\\-methods/([^/]++)/(*:47)'
.'|get\\-method/([^/]++)/(*:75)'
.'|head\\-method/([^/]++)/(*:104)'
.'|post\\-method/([^/]++)/(*:134)'
.'|no\\-methods/([^/]++)(*:46)'
.'|get\\-method/([^/]++)(*:73)'
.'|head\\-method/([^/]++)(*:101)'
.'|post\\-method/([^/]++)(*:130)'
.')'
.'|/not\\-trailing/regex/(?'
.'|no\\-methods/([^/]++)(*:187)'
.'|get\\-method/([^/]++)(*:215)'
.'|head\\-method/([^/]++)(*:244)'
.'|post\\-method/([^/]++)(*:273)'
.'|no\\-methods/([^/]++)(*:183)'
.'|get\\-method/([^/]++)(*:211)'
.'|head\\-method/([^/]++)(*:240)'
.'|post\\-method/([^/]++)(*:269)'
.')'
.')$}sD',
.')(?:/?)$}sD',
);
$this->dynamicRoutes = array(
46 => array(array(array('_route' => 'regex_trailing_slash_no_methods'), array('param'), null, null, true, null)),
73 => array(array(array('_route' => 'regex_trailing_slash_GET_method'), array('param'), array('GET' => 0), null, true, null)),
101 => array(array(array('_route' => 'regex_trailing_slash_HEAD_method'), array('param'), array('HEAD' => 0), null, true, null)),
130 => array(array(array('_route' => 'regex_trailing_slash_POST_method'), array('param'), array('POST' => 0), null, true, null)),
183 => array(array(array('_route' => 'regex_not_trailing_slash_no_methods'), array('param'), null, null, false, null)),
211 => array(array(array('_route' => 'regex_not_trailing_slash_GET_method'), array('param'), array('GET' => 0), null, false, null)),
240 => array(array(array('_route' => 'regex_not_trailing_slash_HEAD_method'), array('param'), array('HEAD' => 0), null, false, null)),
269 => array(array(array('_route' => 'regex_not_trailing_slash_POST_method'), array('param'), array('POST' => 0), null, false, null)),
);
foreach ($regexList as $offset => $regex) {
while (preg_match($regex, $matchedPathinfo, $matches)) {
switch ($m = (int) $matches['MARK']) {
default:
$routes = array(
47 => array(array('_route' => 'regex_trailing_slash_no_methods'), array('param'), null, null),
75 => array(array('_route' => 'regex_trailing_slash_GET_method'), array('param'), array('GET' => 0), null),
104 => array(array('_route' => 'regex_trailing_slash_HEAD_method'), array('param'), array('HEAD' => 0), null),
134 => array(array('_route' => 'regex_trailing_slash_POST_method'), array('param'), array('POST' => 0), null),
187 => array(array('_route' => 'regex_not_trailing_slash_no_methods'), array('param'), null, null),
215 => array(array('_route' => 'regex_not_trailing_slash_GET_method'), array('param'), array('GET' => 0), null),
244 => array(array('_route' => 'regex_not_trailing_slash_HEAD_method'), array('param'), array('HEAD' => 0), null),
273 => array(array('_route' => 'regex_not_trailing_slash_POST_method'), array('param'), array('POST' => 0), null),
);
list($ret, $vars, $requiredMethods, $requiredSchemes) = $routes[$m];
foreach ($vars as $i => $v) {
if (isset($matches[1 + $i])) {
$ret[$v] = $matches[1 + $i];
}
}
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
if ($hasRequiredScheme) {
$allow += $requiredMethods;
}
break;
}
if (!$hasRequiredScheme) {
$allowSchemes += $requiredSchemes;
break;
}
return $ret;
}
if (273 === $m) {
break;
}
$regex = substr_replace($regex, 'F', $m - $offset, 1 + strlen($m));
$offset += strlen($m);
}
}
if ('/' === $pathinfo && !$allow && !$allowSchemes) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}
return null;
}
}

View File

@@ -1,7 +1,6 @@
<?php
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherTrait;
use Symfony\Component\Routing\RequestContext;
/**
@@ -10,79 +9,26 @@ use Symfony\Component\Routing\RequestContext;
*/
class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
{
use PhpMatcherTrait;
public function __construct(RequestContext $context)
{
$this->context = $context;
}
public function match($rawPathinfo)
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo);
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
if ('HEAD' === $requestMethod) {
$canonicalMethod = 'GET';
}
$matchedPathinfo = $pathinfo;
$regexList = array(
$this->regexpList = array(
0 => '{^(?'
.'|/(a)(*:11)'
.')$}sD',
.')(?:/?)$}sD',
11 => '{^(?'
.'|/(.)(*:22)'
.')$}sDu',
.')(?:/?)$}sDu',
22 => '{^(?'
.'|/(.)(*:33)'
.')$}sD',
.')(?:/?)$}sD',
);
$this->dynamicRoutes = array(
11 => array(array(array('_route' => 'a'), array('a'), null, null, false, null)),
22 => array(array(array('_route' => 'b'), array('a'), null, null, false, null)),
33 => array(array(array('_route' => 'c'), array('a'), null, null, false, null)),
);
foreach ($regexList as $offset => $regex) {
while (preg_match($regex, $matchedPathinfo, $matches)) {
switch ($m = (int) $matches['MARK']) {
default:
$routes = array(
11 => array(array('_route' => 'a'), array('a'), null, null),
22 => array(array('_route' => 'b'), array('a'), null, null),
33 => array(array('_route' => 'c'), array('a'), null, null),
);
list($ret, $vars, $requiredMethods, $requiredSchemes) = $routes[$m];
foreach ($vars as $i => $v) {
if (isset($matches[1 + $i])) {
$ret[$v] = $matches[1 + $i];
}
}
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
if ($hasRequiredScheme) {
$allow += $requiredMethods;
}
break;
}
if (!$hasRequiredScheme) {
$allowSchemes += $requiredSchemes;
break;
}
return $ret;
}
if (33 === $m) {
break;
}
$regex = substr_replace($regex, 'F', $m - $offset, 1 + strlen($m));
$offset += strlen($m);
}
}
if ('/' === $pathinfo && !$allow && !$allowSchemes) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}
throw $allow ? new MethodNotAllowedException(array_keys($allow)) : new ResourceNotFoundException();
}
}

View File

@@ -1,7 +1,6 @@
<?php
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherTrait;
use Symfony\Component\Routing\RequestContext;
/**
@@ -10,44 +9,18 @@ use Symfony\Component\Routing\RequestContext;
*/
class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
{
use PhpMatcherTrait;
public function __construct(RequestContext $context)
{
$this->context = $context;
}
public function match($rawPathinfo)
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo);
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
$host = strtolower($context->getHost());
if ('HEAD' === $requestMethod) {
$canonicalMethod = 'GET';
}
switch ($pathinfo) {
case '/':
// a
if (preg_match('#^(?P<d>[^\\.]++)\\.e\\.c\\.b\\.a$#sDi', $host, $hostMatches)) {
return $this->mergeDefaults(array('_route' => 'a') + $hostMatches, array());
}
// c
if (preg_match('#^(?P<e>[^\\.]++)\\.e\\.c\\.b\\.a$#sDi', $host, $hostMatches)) {
return $this->mergeDefaults(array('_route' => 'c') + $hostMatches, array());
}
// b
if ('d.c.b.a' === $host) {
return array('_route' => 'b');
}
break;
}
if ('/' === $pathinfo && !$allow && !$allowSchemes) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}
throw $allow ? new MethodNotAllowedException(array_keys($allow)) : new ResourceNotFoundException();
$this->matchHost = true;
$this->staticRoutes = array(
'/' => array(
array(array('_route' => 'a'), '#^(?P<d>[^\\.]++)\\.e\\.c\\.b\\.a$#sDi', null, null, false, null),
array(array('_route' => 'c'), '#^(?P<e>[^\\.]++)\\.e\\.c\\.b\\.a$#sDi', null, null, false, null),
array(array('_route' => 'b'), 'd.c.b.a', null, null, false, null),
),
);
}
}

View File

@@ -0,0 +1,4 @@
foo:
path: '/{foo}'
requirements:
- '\d+'

View File

@@ -84,19 +84,20 @@ class PhpGeneratorDumperTest extends TestCase
$this->assertEquals('/app.php/testing2', $relativeUrlWithoutParameter);
}
public function testDumpWithLocalizedRoutes()
public function testDumpWithSimpleLocalizedRoutes()
{
$this->routeCollection->add('test', (new Route('/foo')));
$this->routeCollection->add('test.en', (new Route('/testing/is/fun'))->setDefault('_locale', 'en')->setDefault('_canonical_route', 'test'));
$this->routeCollection->add('test.nl', (new Route('/testen/is/leuk'))->setDefault('_locale', 'nl')->setDefault('_canonical_route', 'test'));
$code = $this->generatorDumper->dump(array(
'class' => 'LocalizedProjectUrlGenerator',
'class' => 'SimpleLocalizedProjectUrlGenerator',
));
file_put_contents($this->testTmpFilepath, $code);
include $this->testTmpFilepath;
$context = new RequestContext('/app.php');
$projectUrlGenerator = new \LocalizedProjectUrlGenerator($context, null, 'en');
$projectUrlGenerator = new \SimpleLocalizedProjectUrlGenerator($context, null, 'en');
$urlWithDefaultLocale = $projectUrlGenerator->generate('test');
$urlWithSpecifiedLocale = $projectUrlGenerator->generate('test', array('_locale' => 'nl'));
@@ -109,6 +110,57 @@ class PhpGeneratorDumperTest extends TestCase
$this->assertEquals('/app.php/testen/is/leuk', $urlWithSpecifiedLocale);
$this->assertEquals('/app.php/testing/is/fun', $urlWithEnglishContext);
$this->assertEquals('/app.php/testen/is/leuk', $urlWithDutchContext);
// test with full route name
$this->assertEquals('/app.php/testing/is/fun', $projectUrlGenerator->generate('test.en'));
$context->setParameter('_locale', 'de_DE');
// test that it fall backs to another route when there is no matching localized route
$this->assertEquals('/app.php/foo', $projectUrlGenerator->generate('test'));
}
/**
* @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
* @expectedExceptionMessage Unable to generate a URL for the named route "test" as such route does not exist.
*/
public function testDumpWithRouteNotFoundLocalizedRoutes()
{
$this->routeCollection->add('test.en', (new Route('/testing/is/fun'))->setDefault('_locale', 'en')->setDefault('_canonical_route', 'test'));
$code = $this->generatorDumper->dump(array(
'class' => 'RouteNotFoundLocalizedProjectUrlGenerator',
));
file_put_contents($this->testTmpFilepath, $code);
include $this->testTmpFilepath;
$projectUrlGenerator = new \RouteNotFoundLocalizedProjectUrlGenerator(new RequestContext('/app.php'), null, 'pl_PL');
$projectUrlGenerator->generate('test');
}
public function testDumpWithFallbackLocaleLocalizedRoutes()
{
$this->routeCollection->add('test.en', (new Route('/testing/is/fun'))->setDefault('_canonical_route', 'test'));
$this->routeCollection->add('test.nl', (new Route('/testen/is/leuk'))->setDefault('_canonical_route', 'test'));
$this->routeCollection->add('test.fr', (new Route('/tester/est/amusant'))->setDefault('_canonical_route', 'test'));
$code = $this->generatorDumper->dump(array(
'class' => 'FallbackLocaleLocalizedProjectUrlGenerator',
));
file_put_contents($this->testTmpFilepath, $code);
include $this->testTmpFilepath;
$context = new RequestContext('/app.php');
$context->setParameter('_locale', 'en_GB');
$projectUrlGenerator = new \FallbackLocaleLocalizedProjectUrlGenerator($context, null, null);
// test with context _locale
$this->assertEquals('/app.php/testing/is/fun', $projectUrlGenerator->generate('test'));
// test with parameters _locale
$this->assertEquals('/app.php/testen/is/leuk', $projectUrlGenerator->generate('test', array('_locale' => 'nl_BE')));
$projectUrlGenerator = new \FallbackLocaleLocalizedProjectUrlGenerator(new RequestContext('/app.php'), null, 'fr_CA');
// test with default locale
$this->assertEquals('/app.php/tester/est/amusant', $projectUrlGenerator->generate('test'));
}
public function testDumpWithTooManyRoutes()

View File

@@ -33,6 +33,7 @@ use Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\MissingRouteName
use Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\NothingButNameController;
use Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\PrefixedActionLocalizedRouteController;
use Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\PrefixedActionPathController;
use Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\RequirementsWithoutPlaceholderNameController;
use Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\RouteWithPrefixController;
class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
@@ -87,11 +88,25 @@ class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
$this->assertEquals('/path', $routes->get('action')->getPath());
}
/**
* @group legacy
* @expectedDeprecation A placeholder name must be a string (0 given). Did you forget to specify the placeholder key for the requirement "foo" in "Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\RequirementsWithoutPlaceholderNameController"?
* @expectedDeprecation A placeholder name must be a string (1 given). Did you forget to specify the placeholder key for the requirement "\d+" in "Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\RequirementsWithoutPlaceholderNameController"?
* @expectedDeprecation A placeholder name must be a string (0 given). Did you forget to specify the placeholder key for the requirement "foo" of route "foo" in "Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\RequirementsWithoutPlaceholderNameController::foo()"?
* @expectedDeprecation A placeholder name must be a string (1 given). Did you forget to specify the placeholder key for the requirement "\d+" of route "foo" in "Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\RequirementsWithoutPlaceholderNameController::foo()"?
*/
public function testRequirementsWithoutPlaceholderName()
{
$this->loader->load(RequirementsWithoutPlaceholderNameController::class);
}
public function testInvokableControllerLoader()
{
$routes = $this->loader->load(InvokableController::class);
$this->assertCount(1, $routes);
$this->assertEquals('/here', $routes->get('lol')->getPath());
$this->assertEquals(array('GET', 'POST'), $routes->get('lol')->getMethods());
$this->assertEquals(array('https'), $routes->get('lol')->getSchemes());
}
public function testInvokableLocalizedControllerLoading()
@@ -134,7 +149,7 @@ class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
$this->assertEquals('/the/path', $routes->get('post')->getPath());
}
public function testLocalizedMethodActionControllers()
public function testInvokableClassRouteLoadWithMethodAnnotation()
{
$routes = $this->loader->load(LocalizedMethodActionControllers::class);
$this->assertCount(4, $routes);

View File

@@ -304,4 +304,14 @@ class YamlFileLoaderTest extends TestCase
$this->assertEquals('/slash/', $routeCollection->get('a_app_homepage')->getPath());
$this->assertEquals('/no-slash', $routeCollection->get('b_app_homepage')->getPath());
}
/**
* @group legacy
* @expectedDeprecation A placeholder name must be a string (0 given). Did you forget to specify the placeholder key for the requirement "\d+" of route "foo" in "%srequirements_without_placeholder_name.yml"?
*/
public function testRequirementsWithoutPlaceholderName()
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$loader->load('requirements_without_placeholder_name.yml');
}
}

View File

@@ -472,9 +472,6 @@ class PhpMatcherDumperTest extends TestCase
);
}
/**
* @param $dumper
*/
private function generateDumpedMatcher(RouteCollection $collection, $redirectableStub = false)
{
$options = array('class' => $this->matcherClass);

View File

@@ -141,6 +141,25 @@ class RedirectableUrlMatcherTest extends UrlMatcherTest
$this->assertSame(array('_route' => 'foo'), $matcher->match('/foo'));
}
public function testFallbackPage()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo/'));
$coll->add('bar', new Route('/{name}'));
$matcher = $this->getUrlMatcher($coll);
$matcher->expects($this->once())->method('redirect')->with('/foo/', 'foo')->will($this->returnValue(array('_route' => 'foo')));
$this->assertSame(array('_route' => 'foo'), $matcher->match('/foo'));
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo'));
$coll->add('bar', new Route('/{name}/'));
$matcher = $this->getUrlMatcher($coll);
$matcher->expects($this->once())->method('redirect')->with('/foo', 'foo')->will($this->returnValue(array('_route' => 'foo')));
$this->assertSame(array('_route' => 'foo'), $matcher->match('/foo/'));
}
public function testMissingTrailingSlashAndScheme()
{
$coll = new RouteCollection();

View File

@@ -455,6 +455,9 @@ class UrlMatcherTest extends TestCase
{
$coll = new RouteCollection();
$route = new Route('/foo/{bar}');
$route->setCondition('request.getBaseUrl() == "/bar"');
$coll->add('bar', $route);
$route = new Route('/foo/{bar}');
$route->setCondition('request.getBaseUrl() == "/sub/front.php" and request.getPathInfo() == "/foo/bar"');
$coll->add('foo', $route);
$matcher = $this->getUrlMatcher($coll, new RequestContext('/sub/front.php'));
@@ -680,6 +683,15 @@ class UrlMatcherTest extends TestCase
$this->assertEquals('b', $matcher->match('/bar/abc.123')['_route']);
}
public function testSlashVariant()
{
$coll = new RouteCollection();
$coll->add('a', new Route('/foo/{bar}', array(), array('bar' => '.*')));
$matcher = $this->getUrlMatcher($coll);
$this->assertEquals('a', $matcher->match('/foo/')['_route']);
}
protected function getUrlMatcher(RouteCollection $routes, RequestContext $context = null)
{
return new UrlMatcher($routes, $context ?: new RequestContext());