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

@@ -1,6 +1,11 @@
CHANGELOG
=========
4.2.0
-----
* added fallback to cultureless locale for internationalized routes
4.0.0
-----

View File

@@ -16,6 +16,6 @@ namespace Symfony\Component\Routing\Exception;
*
* @author Alexandre Salomé <alexandre.salome@gmail.com>
*/
interface ExceptionInterface
interface ExceptionInterface extends \Throwable
{
}

View File

@@ -113,10 +113,17 @@ EOF;
?? $this->context->getParameter('_locale')
?: $this->defaultLocale;
if (null !== $locale && (self::$declaredRoutes[$name.'.'.$locale][1]['_canonical_route'] ?? null) === $name) {
unset($parameters['_locale']);
$name .= '.'.$locale;
} elseif (!isset(self::$declaredRoutes[$name])) {
if (null !== $locale && null !== $name) {
do {
if ((self::$declaredRoutes[$name.'.'.$locale][1]['_canonical_route'] ?? null) === $name) {
unset($parameters['_locale']);
$name .= '.'.$locale;
break;
}
} while (false !== $locale = strstr($locale, '_', true));
}
if (!isset(self::$declaredRoutes[$name])) {
throw new RouteNotFoundException(sprintf('Unable to generate a URL for the named route "%s" as such route does not exist.', $name));
}

View File

@@ -112,13 +112,21 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt
*/
public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH)
{
$route = null;
$locale = $parameters['_locale']
?? $this->context->getParameter('_locale')
?: $this->defaultLocale;
if (null !== $locale && null !== ($route = $this->routes->get($name.'.'.$locale)) && $route->getDefault('_canonical_route') === $name) {
unset($parameters['_locale']);
} elseif (null === $route = $this->routes->get($name)) {
if (null !== $locale) {
do {
if (null !== ($route = $this->routes->get($name.'.'.$locale)) && $route->getDefault('_canonical_route') === $name) {
unset($parameters['_locale']);
break;
}
} while (false !== $locale = strstr($locale, '_', true));
}
if (null === $route = $route ?? $this->routes->get($name)) {
throw new RouteNotFoundException(sprintf('Unable to generate a URL for the named route "%s" as such route does not exist.', $name));
}
@@ -254,10 +262,7 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt
});
// extract fragment
$fragment = '';
if (isset($defaults['_fragment'])) {
$fragment = $defaults['_fragment'];
}
$fragment = $defaults['_fragment'] ?? '';
if (isset($extra['_fragment'])) {
$fragment = $extra['_fragment'];

View File

@@ -120,12 +120,9 @@ abstract class AnnotationClassLoader implements LoaderInterface
}
if (0 === $collection->count() && $class->hasMethod('__invoke')) {
$globals = $this->resetGlobals();
foreach ($this->reader->getClassAnnotations($class) as $annot) {
if ($annot instanceof $this->routeAnnotationClass) {
$globals['path'] = '';
$globals['name'] = '';
$globals['localized_paths'] = array();
$this->addRoute($collection, $annot, $globals, $class, $class->getMethod('__invoke'));
}
}
@@ -142,8 +139,16 @@ abstract class AnnotationClassLoader implements LoaderInterface
}
$name = $globals['name'].$name;
$requirements = $annot->getRequirements();
foreach ($requirements as $placeholder => $requirement) {
if (\is_int($placeholder)) {
@trigger_error(sprintf('A placeholder name must be a string (%d given). Did you forget to specify the placeholder key for the requirement "%s" of route "%s" in "%s::%s()"?', $placeholder, $requirement, $name, $class->getName(), $method->getName()), E_USER_DEPRECATED);
}
}
$defaults = array_replace($globals['defaults'], $annot->getDefaults());
$requirements = array_replace($globals['requirements'], $annot->getRequirements());
$requirements = array_replace($globals['requirements'], $requirements);
$options = array_replace($globals['options'], $annot->getOptions());
$schemes = array_merge($globals['schemes'], $annot->getSchemes());
$methods = array_merge($globals['methods'], $annot->getMethods());
@@ -254,18 +259,7 @@ abstract class AnnotationClassLoader implements LoaderInterface
protected function getGlobals(\ReflectionClass $class)
{
$globals = array(
'path' => null,
'localized_paths' => array(),
'requirements' => array(),
'options' => array(),
'defaults' => array(),
'schemes' => array(),
'methods' => array(),
'host' => '',
'condition' => '',
'name' => '',
);
$globals = $this->resetGlobals();
if ($annot = $this->reader->getClassAnnotation($class, $this->routeAnnotationClass)) {
if (null !== $annot->getName()) {
@@ -305,11 +299,33 @@ abstract class AnnotationClassLoader implements LoaderInterface
if (null !== $annot->getCondition()) {
$globals['condition'] = $annot->getCondition();
}
foreach ($globals['requirements'] as $placeholder => $requirement) {
if (\is_int($placeholder)) {
@trigger_error(sprintf('A placeholder name must be a string (%d given). Did you forget to specify the placeholder key for the requirement "%s" in "%s"?', $placeholder, $requirement, $class->getName()), E_USER_DEPRECATED);
}
}
}
return $globals;
}
private function resetGlobals()
{
return array(
'path' => null,
'localized_paths' => array(),
'requirements' => array(),
'options' => array(),
'defaults' => array(),
'schemes' => array(),
'methods' => array(),
'host' => '',
'condition' => '',
'name' => '',
);
}
protected function createRoute($path, $defaults, $requirements, $options, $host, $schemes, $methods, $condition)
{
return new Route($path, $defaults, $requirements, $options, $host, $schemes, $methods, $condition);

View File

@@ -32,7 +32,7 @@ class AnnotationFileLoader extends FileLoader
public function __construct(FileLocatorInterface $locator, AnnotationClassLoader $loader)
{
if (!\function_exists('token_get_all')) {
throw new \RuntimeException('The Tokenizer extension is required for the routing annotation loaders.');
throw new \LogicException('The Tokenizer extension is required for the routing annotation loaders.');
}
parent::__construct($locator);

View File

@@ -116,6 +116,12 @@ class YamlFileLoader extends FileLoader
$methods = isset($config['methods']) ? $config['methods'] : array();
$condition = isset($config['condition']) ? $config['condition'] : null;
foreach ($requirements as $placeholder => $requirement) {
if (\is_int($placeholder)) {
@trigger_error(sprintf('A placeholder name must be a string (%d given). Did you forget to specify the placeholder key for the requirement "%s" of route "%s" in "%s"?', $placeholder, $requirement, $name, $path), E_USER_DEPRECATED);
}
}
if (isset($config['controller'])) {
$defaults['_controller'] = $config['controller'];
}
@@ -244,28 +250,16 @@ class YamlFileLoader extends FileLoader
throw new \InvalidArgumentException(sprintf('The definition of "%s" in "%s" must be a YAML array.', $name, $path));
}
if ($extraKeys = array_diff(array_keys($config), self::$availableKeys)) {
throw new \InvalidArgumentException(sprintf(
'The routing file "%s" contains unsupported keys for "%s": "%s". Expected one of: "%s".',
$path, $name, implode('", "', $extraKeys), implode('", "', self::$availableKeys)
));
throw new \InvalidArgumentException(sprintf('The routing file "%s" contains unsupported keys for "%s": "%s". Expected one of: "%s".', $path, $name, implode('", "', $extraKeys), implode('", "', self::$availableKeys)));
}
if (isset($config['resource']) && isset($config['path'])) {
throw new \InvalidArgumentException(sprintf(
'The routing file "%s" must not specify both the "resource" key and the "path" key for "%s". Choose between an import and a route definition.',
$path, $name
));
throw new \InvalidArgumentException(sprintf('The routing file "%s" must not specify both the "resource" key and the "path" key for "%s". Choose between an import and a route definition.', $path, $name));
}
if (!isset($config['resource']) && isset($config['type'])) {
throw new \InvalidArgumentException(sprintf(
'The "type" key for the route definition "%s" in "%s" is unsupported. It is only available for imports in combination with the "resource" key.',
$name, $path
));
throw new \InvalidArgumentException(sprintf('The "type" key for the route definition "%s" in "%s" is unsupported. It is only available for imports in combination with the "resource" key.', $name, $path));
}
if (!isset($config['resource']) && !isset($config['path'])) {
throw new \InvalidArgumentException(sprintf(
'You must define a "path" for the route "%s" in file "%s".',
$name, $path
));
throw new \InvalidArgumentException(sprintf('You must define a "path" for the route "%s" in file "%s".', $name, $path));
}
if (isset($config['controller']) && isset($config['defaults']['_controller'])) {
throw new \InvalidArgumentException(sprintf('The routing file "%s" must not specify both the "controller" key and the defaults key "_controller" for "%s".', $path, $name));

View File

@@ -13,7 +13,6 @@ namespace Symfony\Component\Routing\Matcher\Dumper;
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
use Symfony\Component\Routing\Matcher\RedirectableUrlMatcherInterface;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
@@ -56,13 +55,11 @@ class PhpMatcherDumper extends MatcherDumper
// trailing slash support is only enabled if we know how to redirect the user
$interfaces = class_implements($options['base_class']);
$supportsRedirections = isset($interfaces[RedirectableUrlMatcherInterface::class]);
return <<<EOF
<?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;
/**
@@ -71,12 +68,12 @@ use Symfony\Component\Routing\RequestContext;
*/
class {$options['class']} extends {$options['base_class']}
{
use PhpMatcherTrait;
public function __construct(RequestContext \$context)
{
\$this->context = \$context;
}
{$this->generateMatchMethod($supportsRedirections)}
{$this->generateProperties()} }
}
EOF;
@@ -90,7 +87,7 @@ EOF;
/**
* Generates the code for the match method implementing UrlMatcherInterface.
*/
private function generateMatchMethod(bool $supportsRedirections): string
private function generateProperties(): string
{
// Group hosts by same-suffix, re-order when possible
$matchHost = false;
@@ -103,86 +100,25 @@ EOF;
$routes->addRoute($host ?: '/(.*)', array($name, $route));
}
$routes = $matchHost ? $routes->populateCollection(new RouteCollection()) : $this->getRoutes();
$code = rtrim($this->compileRoutes($routes, $matchHost), "\n");
$fetchHost = $matchHost ? " \$host = strtolower(\$context->getHost());\n" : '';
$code = <<<EOF
{
\$allow = \$allowSchemes = array();
\$pathinfo = rawurldecode(\$rawPathinfo);
\$context = \$this->context;
\$requestMethod = \$canonicalMethod = \$context->getMethod();
{$fetchHost}
if ('HEAD' === \$requestMethod) {
\$canonicalMethod = 'GET';
if ($matchHost) {
$code = '$this->matchHost = true;'."\n";
$routes = $routes->populateCollection(new RouteCollection());
} else {
$code = '';
$routes = $this->getRoutes();
}
$code
EOF;
if ($supportsRedirections) {
return <<<'EOF'
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
EOF
.$code."\n return null;\n }";
}
return " public function match(\$rawPathinfo)\n".$code."\n throw \$allow ? new MethodNotAllowedException(array_keys(\$allow)) : new ResourceNotFoundException();\n }";
}
/**
* Generates PHP code to match a RouteCollection with all its routes.
*/
private function compileRoutes(RouteCollection $routes, bool $matchHost): string
{
list($staticRoutes, $dynamicRoutes) = $this->groupStaticRoutes($routes);
$code = $this->compileStaticRoutes($staticRoutes, $matchHost);
$conditions = array(null);
$code .= $this->compileStaticRoutes($staticRoutes, $conditions);
$chunkLimit = \count($dynamicRoutes);
while (true) {
try {
$this->signalingException = new \RuntimeException('preg_match(): Compilation failed: regular expression is too large');
$code .= $this->compileDynamicRoutes($dynamicRoutes, $matchHost, $chunkLimit);
$code .= $this->compileDynamicRoutes($dynamicRoutes, $matchHost, $chunkLimit, $conditions);
break;
} catch (\Exception $e) {
if (1 < $chunkLimit && $this->signalingException === $e) {
@@ -193,12 +129,24 @@ EOF
}
}
// used to display the Welcome Page in apps that don't define a homepage
$code .= " if ('/' === \$pathinfo && !\$allow && !\$allowSchemes) {\n";
$code .= " throw new Symfony\Component\Routing\Exception\NoConfigurationException();\n";
$code .= " }\n";
unset($conditions[0]);
return $code;
if (!$conditions) {
return $this->indent($code, 2);
}
foreach ($conditions as $expression => $condition) {
$conditions[$expression] = "case {$condition}: return {$expression};";
}
return $this->indent($code, 2).<<<EOF
\$this->checkCondition = static function (\$condition, \$context, \$request) {
switch (\$condition) {
{$this->indent(implode("\n", $conditions), 4)}
}
};
EOF;
}
/**
@@ -213,9 +161,18 @@ EOF
$compiledRoute = $route->compile();
$hostRegex = $compiledRoute->getHostRegex();
$regex = $compiledRoute->getRegex();
if ($hasTrailingSlash = '/' !== $route->getPath()) {
$pos = strrpos($regex, '$');
$hasTrailingSlash = '/' === $regex[$pos - 1];
$regex = substr_replace($regex, '/?$', $pos - $hasTrailingSlash, 1 + $hasTrailingSlash);
}
if (!$compiledRoute->getPathVariables()) {
$host = !$compiledRoute->getHostVariables() ? $route->getHost() : '';
$url = $route->getPath();
if ($hasTrailingSlash) {
$url = substr($url, 0, -1);
}
foreach ($dynamicRegex as list($hostRx, $rx)) {
if (preg_match($rx, $url) && (!$host || !$hostRx || preg_match($hostRx, $host))) {
$dynamicRegex[] = array($hostRegex, $regex);
@@ -224,7 +181,7 @@ EOF
}
}
$staticRoutes[$url][$name] = $route;
$staticRoutes[$url][$name] = array($route, $hasTrailingSlash);
} else {
$dynamicRegex[] = array($hostRegex, $regex);
$dynamicRoutes->add($name, $route);
@@ -242,58 +199,26 @@ EOF
*
* @throws \LogicException
*/
private function compileStaticRoutes(array $staticRoutes, bool $matchHost): string
private function compileStaticRoutes(array $staticRoutes, array &$conditions): string
{
if (!$staticRoutes) {
return '';
}
$code = $default = '';
$code = '';
foreach ($staticRoutes as $url => $routes) {
if (1 === \count($routes)) {
foreach ($routes as $name => $route) {
}
if (!$route->getCondition()) {
$defaults = $route->getDefaults();
if (isset($defaults['_canonical_route'])) {
$name = $defaults['_canonical_route'];
unset($defaults['_canonical_route']);
}
$default .= sprintf(
"%s => array(%s, %s, %s, %s),\n",
self::export($url),
self::export(array('_route' => $name) + $defaults),
self::export(!$route->compile()->getHostVariables() ? $route->getHost() : $route->compile()->getHostRegex() ?: null),
self::export(array_flip($route->getMethods()) ?: null),
self::export(array_flip($route->getSchemes()) ?: null)
);
continue;
}
$code .= self::export($url)." => array(\n";
foreach ($routes as $name => list($route, $hasTrailingSlash)) {
$code .= $this->compileRoute($route, $name, !$route->compile()->getHostVariables() ? $route->getHost() : $route->compile()->getHostRegex() ?: null, $hasTrailingSlash, $conditions);
}
$code .= sprintf(" case %s:\n", self::export($url));
foreach ($routes as $name => $route) {
$code .= $this->compileRoute($route, $name, true);
}
$code .= " break;\n";
$code .= "),\n";
}
if ($default) {
$code .= <<<EOF
default:
\$routes = array(
{$this->indent($default, 4)} );
if (!isset(\$routes[\$pathinfo])) {
break;
}
list(\$ret, \$requiredHost, \$requiredMethods, \$requiredSchemes) = \$routes[\$pathinfo];
{$this->compileSwitchDefault(false, $matchHost)}
EOF;
if ($code) {
return "\$this->staticRoutes = array(\n{$this->indent($code, 1)});\n";
}
return sprintf(" switch (\$pathinfo) {\n%s }\n\n", $this->indent($code));
return $code;
}
/**
@@ -314,7 +239,7 @@ EOF;
* matching-but-failing subpattern is blacklisted by replacing its name by "(*F)", which forces a failure-to-match.
* To ease this backlisting operation, the name of subpatterns is also the string offset where the replacement should occur.
*/
private function compileDynamicRoutes(RouteCollection $collection, bool $matchHost, int $chunkLimit): string
private function compileDynamicRoutes(RouteCollection $collection, bool $matchHost, int $chunkLimit, array &$conditions): string
{
if (!$collection->all()) {
return '';
@@ -322,8 +247,7 @@ EOF;
$code = '';
$state = (object) array(
'regex' => '',
'switch' => '',
'default' => '',
'routes' => '',
'mark' => 0,
'markTail' => 0,
'hostVars' => array(),
@@ -367,7 +291,7 @@ EOF;
}
$prev = false;
$rx = '{^(?';
$code .= "\n {$state->mark} => ".self::export($rx);
$code .= "\n {$state->mark} => ".self::export($rx);
$state->mark += \strlen($rx);
$state->regex = $rx;
@@ -383,7 +307,7 @@ EOF;
$state->hostVars = array();
}
$state->mark += \strlen($rx = ($prev ? ')' : '')."|{$hostRegex}(?");
$code .= "\n .".self::export($rx);
$code .= "\n .".self::export($rx);
$state->regex .= $rx;
$prev = true;
}
@@ -394,17 +318,21 @@ EOF;
$state->vars = array();
$regex = preg_replace_callback('#\?P<([^>]++)>#', $state->getVars, $rx[1]);
$tree->addRoute($regex, array($name, $regex, $state->vars, $route));
if ($hasTrailingSlash = '/' !== $regex && '/' === $regex[-1]) {
$regex = substr($regex, 0, -1);
}
$tree->addRoute($regex, array($name, $regex, $state->vars, $route, $hasTrailingSlash));
}
$code .= $this->compileStaticPrefixCollection($tree, $state);
$code .= $this->compileStaticPrefixCollection($tree, $state, 0, $conditions);
}
if ($matchHost) {
$code .= "\n .')'";
$code .= "\n .')'";
$state->regex .= ')';
}
$rx = ")$}{$modifiers}";
$code .= "\n .'{$rx}',";
$rx = ")(?:/?)$}{$modifiers}";
$code .= "\n .'{$rx}',";
$state->regex .= $rx;
$state->markTail = 0;
@@ -417,39 +345,10 @@ EOF;
}
}
if ($state->default) {
$state->switch .= <<<EOF
default:
\$routes = array(
{$this->indent($state->default, 4)} );
list(\$ret, \$vars, \$requiredMethods, \$requiredSchemes) = \$routes[\$m];
{$this->compileSwitchDefault(true, $matchHost)}
EOF;
}
$matchedPathinfo = $matchHost ? '$host.\'.\'.$pathinfo' : '$pathinfo';
unset($state->getVars);
return <<<EOF
\$matchedPathinfo = {$matchedPathinfo};
\$regexList = array({$code}
);
foreach (\$regexList as \$offset => \$regex) {
while (preg_match(\$regex, \$matchedPathinfo, \$matches)) {
switch (\$m = (int) \$matches['MARK']) {
{$this->indent($state->switch, 3)} }
if ({$state->mark} === \$m) {
break;
}
\$regex = substr_replace(\$regex, 'F', \$m - \$offset, 1 + strlen(\$m));
\$offset += strlen(\$m);
}
}
EOF;
return "\$this->regexpList = array({$code}\n);\n"
."\$this->dynamicRoutes = array(\n{$this->indent($state->routes, 1)});\n";
}
/**
@@ -458,7 +357,7 @@ EOF;
* @param \stdClass $state A simple state object that keeps track of the progress of the compilation,
* and gathers the generated switch's "case" and "default" statements
*/
private function compileStaticPrefixCollection(StaticPrefixCollection $tree, \stdClass $state, int $prefixLen = 0): string
private function compileStaticPrefixCollection(StaticPrefixCollection $tree, \stdClass $state, int $prefixLen, array &$conditions): string
{
$code = '';
$prevRegex = null;
@@ -469,262 +368,72 @@ EOF;
$prevRegex = null;
$prefix = substr($route->getPrefix(), $prefixLen);
$state->mark += \strlen($rx = "|{$prefix}(?");
$code .= "\n .".self::export($rx);
$code .= "\n .".self::export($rx);
$state->regex .= $rx;
$code .= $this->indent($this->compileStaticPrefixCollection($route, $state, $prefixLen + \strlen($prefix)));
$code .= "\n .')'";
$code .= $this->indent($this->compileStaticPrefixCollection($route, $state, $prefixLen + \strlen($prefix), $conditions));
$code .= "\n .')'";
$state->regex .= ')';
++$state->markTail;
continue;
}
list($name, $regex, $vars, $route) = $route;
list($name, $regex, $vars, $route, $hasTrailingSlash) = $route;
$compiledRoute = $route->compile();
$vars = array_merge($state->hostVars, $vars);
if ($compiledRoute->getRegex() === $prevRegex) {
$state->switch = substr_replace($state->switch, $this->compileRoute($route, $name, false)."\n", -19, 0);
$state->routes = substr_replace($state->routes, $this->compileRoute($route, $name, $vars, $hasTrailingSlash, $conditions), -3, 0);
continue;
}
$state->mark += 3 + $state->markTail + \strlen($regex) - $prefixLen;
$state->markTail = 2 + \strlen($state->mark);
$rx = sprintf('|%s(*:%s)', substr($regex, $prefixLen), $state->mark);
$code .= "\n .".self::export($rx);
$code .= "\n .".self::export($rx);
$state->regex .= $rx;
$vars = array_merge($state->hostVars, $vars);
if (!$route->getCondition() && (!\is_array($next = $routes[1 + $i] ?? null) || $regex !== $next[1])) {
$prevRegex = null;
$defaults = $route->getDefaults();
if (isset($defaults['_canonical_route'])) {
$name = $defaults['_canonical_route'];
unset($defaults['_canonical_route']);
}
$state->default .= sprintf(
"%s => array(%s, %s, %s, %s),\n",
$state->mark,
self::export(array('_route' => $name) + $defaults),
self::export($vars),
self::export(array_flip($route->getMethods()) ?: null),
self::export(array_flip($route->getSchemes()) ?: null)
);
} else {
$prevRegex = $compiledRoute->getRegex();
$combine = ' $matches = array(';
foreach ($vars as $j => $m) {
$combine .= sprintf('%s => $matches[%d] ?? null, ', self::export($m), 1 + $j);
}
$combine = $vars ? substr_replace($combine, ");\n\n", -2) : '';
$state->switch .= <<<EOF
case {$state->mark}:
{$combine}{$this->compileRoute($route, $name, false)}
break;
EOF;
}
$prevRegex = $compiledRoute->getRegex();
$state->routes .= sprintf("%s => array(\n%s),\n", $state->mark, $this->compileRoute($route, $name, $vars, $hasTrailingSlash, $conditions));
}
return $code;
}
/**
* A simple helper to compiles the switch's "default" for both static and dynamic routes.
*/
private function compileSwitchDefault(bool $hasVars, bool $matchHost): string
{
if ($hasVars) {
$code = <<<EOF
foreach (\$vars as \$i => \$v) {
if (isset(\$matches[1 + \$i])) {
\$ret[\$v] = \$matches[1 + \$i];
}
}
EOF;
} elseif ($matchHost) {
$code = <<<EOF
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);
}
}
EOF;
} else {
$code = '';
}
$code .= <<<EOF
\$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;
EOF;
return $code;
}
/**
* Compiles a single Route to PHP code used to match it against the path info.
*
* @throws \LogicException
*/
private function compileRoute(Route $route, string $name, bool $checkHost): string
private function compileRoute(Route $route, string $name, $vars, bool $hasTrailingSlash, array &$conditions): string
{
$code = '';
$compiledRoute = $route->compile();
$conditions = array();
$matches = (bool) $compiledRoute->getPathVariables();
$hostMatches = (bool) $compiledRoute->getHostVariables();
$methods = array_flip($route->getMethods());
if ($route->getCondition()) {
$expression = $this->getExpressionLanguage()->compile($route->getCondition(), array('context', 'request'));
if (false !== strpos($expression, '$request')) {
$conditions[] = '($request = $request ?? $this->request ?: $this->createRequest($pathinfo))';
}
$conditions[] = $expression;
}
if (!$checkHost || !$compiledRoute->getHostRegex()) {
// no-op
} elseif ($hostMatches) {
$conditions[] = sprintf('preg_match(%s, $host, $hostMatches)', self::export($compiledRoute->getHostRegex()));
} else {
$conditions[] = sprintf('%s === $host', self::export($route->getHost()));
}
$conditions = implode(' && ', $conditions);
if ($conditions) {
$code .= <<<EOF
// $name
if ($conditions) {
EOF;
} else {
$code .= " // {$name}\n";
}
$gotoname = 'not_'.preg_replace('/[^A-Za-z0-9_]/', '', $name);
// the offset where the return value is appended below, with indendation
$retOffset = 12 + \strlen($code);
$defaults = $route->getDefaults();
if (isset($defaults['_canonical_route'])) {
$name = $defaults['_canonical_route'];
unset($defaults['_canonical_route']);
}
// optimize parameters array
if ($matches || $hostMatches) {
$vars = array("array('_route' => '$name')");
if ($matches || ($hostMatches && !$checkHost)) {
$vars[] = '$matches';
}
if ($hostMatches && $checkHost) {
$vars[] = '$hostMatches';
}
$code .= sprintf(
" \$ret = \$this->mergeDefaults(%s, %s);\n",
implode(' + ', $vars),
self::export($defaults)
);
} elseif ($defaults) {
$code .= sprintf(" \$ret = %s;\n", self::export(array('_route' => $name) + $defaults));
if ($condition = $route->getCondition()) {
$condition = $this->getExpressionLanguage()->compile($condition, array('context', 'request'));
$condition = $conditions[$condition] ?? $conditions[$condition] = (false !== strpos($condition, '$request') ? 1 : -1) * \count($conditions);
} else {
$code .= sprintf(" \$ret = array('_route' => '%s');\n", $name);
$condition = 'null';
}
if ($methods) {
$methodVariable = isset($methods['GET']) ? '$canonicalMethod' : '$requestMethod';
$methods = self::export($methods);
}
if ($schemes = $route->getSchemes()) {
$schemes = self::export(array_flip($schemes));
if ($methods) {
$code .= <<<EOF
\$requiredSchemes = $schemes;
\$hasRequiredScheme = isset(\$requiredSchemes[\$context->getScheme()]);
if (!isset((\$a = {$methods})[{$methodVariable}])) {
if (\$hasRequiredScheme) {
\$allow += \$a;
}
goto $gotoname;
}
if (!\$hasRequiredScheme) {
\$allowSchemes += \$requiredSchemes;
goto $gotoname;
}
EOF;
} else {
$code .= <<<EOF
\$requiredSchemes = $schemes;
if (!isset(\$requiredSchemes[\$context->getScheme()])) {
\$allowSchemes += \$requiredSchemes;
goto $gotoname;
}
EOF;
}
} elseif ($methods) {
$code .= <<<EOF
if (!isset((\$a = {$methods})[{$methodVariable}])) {
\$allow += \$a;
goto $gotoname;
}
EOF;
}
if ($schemes || $methods) {
$code .= " return \$ret;\n";
} else {
$code = substr_replace($code, 'return', $retOffset, 6);
}
if ($conditions) {
$code .= " }\n";
} elseif ($schemes || $methods) {
$code .= ' ';
}
if ($schemes || $methods) {
$code .= " $gotoname:\n";
}
return $conditions ? $this->indent($code) : $code;
return sprintf(
" array(%s, %s, %s, %s, %s, %s),\n",
self::export(array('_route' => $name) + $defaults),
self::export($vars),
self::export(array_flip($route->getMethods()) ?: null),
self::export(array_flip($route->getSchemes()) ?: null),
self::export($hasTrailingSlash),
$condition
);
}
private function getExpressionLanguage()
{
if (null === $this->expressionLanguage) {
if (!class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage')) {
throw new \RuntimeException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.');
throw new \LogicException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.');
}
$this->expressionLanguage = new ExpressionLanguage(null, $this->expressionLanguageProviders);
}
@@ -734,6 +443,8 @@ EOF;
private function indent($code, $level = 1)
{
$code = preg_replace('/ => array\(\n (array\(.+),\n\),/', ' => array($1),', $code);
return preg_replace('/^./m', str_repeat(' ', $level).'$0', $code);
}

View File

@@ -0,0 +1,173 @@
<?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\Matcher\Dumper;
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\NoConfigurationException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\Matcher\RedirectableUrlMatcherInterface;
/**
* @author Nicolas Grekas <p@tchwork.com>
*
* @internal
*/
trait PhpMatcherTrait
{
private $matchHost = false;
private $staticRoutes = array();
private $regexpList = array();
private $dynamicRoutes = array();
private $checkCondition;
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 (!$this instanceof RedirectableUrlMatcherInterface) {
throw new ResourceNotFoundException();
}
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();
$trimmedPathinfo = '/' !== $pathinfo && '/' === $pathinfo[-1] ? substr($pathinfo, 0, -1) : $pathinfo;
if ($this->matchHost) {
$host = strtolower($context->getHost());
}
if ('HEAD' === $requestMethod) {
$canonicalMethod = 'GET';
}
foreach ($this->staticRoutes[$trimmedPathinfo] ?? array() as list($ret, $requiredHost, $requiredMethods, $requiredSchemes, $hasTrailingSlash, $condition)) {
if ($condition && !($this->checkCondition)($condition, $context, 0 < $condition ? $request ?? $request = $this->request ?: $this->createRequest($pathinfo) : null)) {
continue;
}
if ('/' === $pathinfo || $hasTrailingSlash === ('/' === $pathinfo[-1])) {
// no-op
} elseif ($this instanceof RedirectableUrlMatcherInterface) {
return null;
} else {
continue;
}
if ($requiredHost) {
if ('#' !== $requiredHost[0] ? $requiredHost !== $host : !preg_match($requiredHost, $host, $hostMatches)) {
continue;
}
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;
}
continue;
}
if (!$hasRequiredScheme) {
$allowSchemes += $requiredSchemes;
continue;
}
return $ret;
}
$matchedPathinfo = $this->matchHost ? $host.'.'.$pathinfo : $pathinfo;
foreach ($this->regexpList as $offset => $regex) {
while (preg_match($regex, $matchedPathinfo, $matches)) {
foreach ($this->dynamicRoutes[$m = (int) $matches['MARK']] as list($ret, $vars, $requiredMethods, $requiredSchemes, $hasTrailingSlash, $condition)) {
if ($condition && !($this->checkCondition)($condition, $context, 0 < $condition ? $request ?? $request = $this->request ?: $this->createRequest($pathinfo) : null)) {
continue;
}
if ('/' === $pathinfo || (!$hasTrailingSlash ? '/' !== $pathinfo[-1] || !preg_match($regex, substr($pathinfo, 0, -1), $n) || $m !== (int) $n['MARK'] : '/' === $pathinfo[-1])) {
// no-op
} elseif ($this instanceof RedirectableUrlMatcherInterface) {
return null;
} else {
continue;
}
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;
}
continue;
}
if (!$hasRequiredScheme) {
$allowSchemes += $requiredSchemes;
continue;
}
return $ret;
}
$regex = substr_replace($regex, 'F', $m - $offset, 1 + \strlen($m));
$offset += \strlen($m);
}
}
if ('/' === $pathinfo && !$allow && !$allowSchemes) {
throw new NoConfigurationException();
}
return null;
}
}

View File

@@ -130,16 +130,43 @@ class UrlMatcher implements UrlMatcherInterface, RequestMatcherInterface
*/
protected function matchCollection($pathinfo, RouteCollection $routes)
{
$supportsTrailingSlash = '/' !== $pathinfo && '' !== $pathinfo && $this instanceof RedirectableUrlMatcherInterface;
foreach ($routes as $name => $route) {
$compiledRoute = $route->compile();
$staticPrefix = $compiledRoute->getStaticPrefix();
// check the static prefix of the URL first. Only use the more expensive preg_match when it matches
if ('' !== $compiledRoute->getStaticPrefix() && 0 !== strpos($pathinfo, $compiledRoute->getStaticPrefix())) {
if ('' === $staticPrefix || 0 === strpos($pathinfo, $staticPrefix)) {
// no-op
} elseif (!$supportsTrailingSlash) {
continue;
} elseif ('/' === $staticPrefix[-1] && substr($staticPrefix, 0, -1) === $pathinfo) {
return;
} elseif ('/' === $pathinfo[-1] && substr($pathinfo, 0, -1) === $staticPrefix) {
return;
} else {
continue;
}
$regex = $compiledRoute->getRegex();
if ($supportsTrailingSlash) {
$pos = strrpos($regex, '$');
$hasTrailingSlash = '/' === $regex[$pos - 1];
$regex = substr_replace($regex, '/?$', $pos - $hasTrailingSlash, 1 + $hasTrailingSlash);
}
if (!preg_match($regex, $pathinfo, $matches)) {
continue;
}
if (!preg_match($compiledRoute->getRegex(), $pathinfo, $matches)) {
continue;
if ($supportsTrailingSlash) {
if (!$hasTrailingSlash && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1))) {
return;
}
if ($hasTrailingSlash && '/' !== $pathinfo[-1]) {
return;
}
}
$hostMatches = array();
@@ -246,7 +273,7 @@ class UrlMatcher implements UrlMatcherInterface, RequestMatcherInterface
{
if (null === $this->expressionLanguage) {
if (!class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage')) {
throw new \RuntimeException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.');
throw new \LogicException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.');
}
$this->expressionLanguage = new ExpressionLanguage(null, $this->expressionLanguageProviders);
}

View File

@@ -29,7 +29,7 @@ class Route implements \Serializable
private $condition = '';
/**
* @var null|CompiledRoute
* @var CompiledRoute|null
*/
private $compiled;

View File

@@ -11,7 +11,7 @@
namespace Symfony\Component\Routing;
use Symfony\Component\Config\Exception\FileLoaderLoadException;
use Symfony\Component\Config\Exception\LoaderLoadException;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Config\Resource\ResourceInterface;
@@ -46,7 +46,7 @@ class RouteCollectionBuilder
/**
* Import an external routing resource and returns the RouteCollectionBuilder.
*
* $routes->import('blog.yml', '/blog');
* $routes->import('blog.yml', '/blog');
*
* @param mixed $resource
* @param string|null $prefix
@@ -54,7 +54,7 @@ class RouteCollectionBuilder
*
* @return self
*
* @throws FileLoaderLoadException
* @throws LoaderLoadException
*/
public function import($resource, $prefix = '/', $type = null)
{
@@ -347,7 +347,7 @@ class RouteCollectionBuilder
*
* @return RouteCollection[]
*
* @throws FileLoaderLoadException If no loader is found
* @throws LoaderLoadException If no loader is found
*/
private function load($resource, string $type = null): array
{
@@ -362,11 +362,11 @@ class RouteCollectionBuilder
}
if (null === $resolver = $this->loader->getResolver()) {
throw new FileLoaderLoadException($resource, null, null, null, $type);
throw new LoaderLoadException($resource, null, null, null, $type);
}
if (false === $loader = $resolver->resolve($resource, $type)) {
throw new FileLoaderLoadException($resource, null, null, null, $type);
throw new LoaderLoadException($resource, null, null, null, $type);
}
$collections = $loader->load($resource, $type);

View File

@@ -375,7 +375,7 @@ class Router implements RouterInterface, RequestMatcherInterface
* Provides the ConfigCache factory implementation, falling back to a
* default implementation if necessary.
*
* @return ConfigCacheFactoryInterface $configCacheFactory
* @return ConfigCacheFactoryInterface
*/
private function getConfigCacheFactory()
{

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());

View File

@@ -19,7 +19,7 @@
"php": "^7.1.3"
},
"require-dev": {
"symfony/config": "~3.4|~4.0",
"symfony/config": "~4.2",
"symfony/http-foundation": "~3.4|~4.0",
"symfony/yaml": "~3.4|~4.0",
"symfony/expression-language": "~3.4|~4.0",
@@ -28,7 +28,7 @@
"psr/log": "~1.0"
},
"conflict": {
"symfony/config": "<3.4",
"symfony/config": "<4.2",
"symfony/dependency-injection": "<3.4",
"symfony/yaml": "<3.4"
},
@@ -49,7 +49,7 @@
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "4.1-dev"
"dev-master": "4.2-dev"
}
}
}

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.2/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"