Speed up url matching for route without variable
This commit is contained in:
parent
98db58ac17
commit
5e94807668
@ -60,17 +60,25 @@ class PhpMatcherDumper extends MatcherDumper
|
||||
$conditions[] = sprintf("isset(\$this->context['method']) && preg_match('#^(%s)$#xi', \$this->context['method'])", $req);
|
||||
}
|
||||
|
||||
if ($compiledRoute->getStaticPrefix()) {
|
||||
$conditions[] = sprintf("0 === strpos(\$url, '%s')", $compiledRoute->getStaticPrefix());
|
||||
}
|
||||
if (!count($compiledRoute->getVariables()) && false !== preg_match('#^(.)\^(?P<url>.*?)\$\1#', $compiledRoute->getRegex(), $m)) {
|
||||
$conditions[] = sprintf("\$url === '%s'", $m['url']);
|
||||
|
||||
$conditions[] = sprintf("preg_match('%s', \$url, \$matches)", $compiledRoute->getRegex());
|
||||
$matches = 'array()';
|
||||
} else {
|
||||
if ($compiledRoute->getStaticPrefix()) {
|
||||
$conditions[] = sprintf("0 === strpos(\$url, '%s')", $compiledRoute->getStaticPrefix());
|
||||
}
|
||||
|
||||
$conditions[] = sprintf("preg_match('%s', \$url, \$matches)", $compiledRoute->getRegex());
|
||||
|
||||
$matches = '$matches';
|
||||
}
|
||||
|
||||
$conditions = implode(' && ', $conditions);
|
||||
|
||||
$code[] = sprintf(<<<EOF
|
||||
if ($conditions) {
|
||||
return array_merge(\$this->mergeDefaults(\$matches, %s), array('_route' => '%s'));
|
||||
return array_merge(\$this->mergeDefaults($matches, %s), array('_route' => '%s'));
|
||||
}
|
||||
|
||||
EOF
|
||||
|
@ -29,6 +29,10 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
|
||||
return array_merge($this->mergeDefaults($matches, array ()), array('_route' => 'bar'));
|
||||
}
|
||||
|
||||
if ($url === '/test/baz') {
|
||||
return array_merge($this->mergeDefaults(array(), array ()), array('_route' => 'baz'));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -38,6 +38,10 @@ class PhpMatcherDumperTest extends \PHPUnit_Framework_TestCase
|
||||
array(),
|
||||
array('_method' => 'GET|head')
|
||||
));
|
||||
$collection->add('baz', new Route(
|
||||
'/test/baz'
|
||||
));
|
||||
|
||||
$dumper = new PhpMatcherDumper($collection);
|
||||
$this->assertStringEqualsFile(self::$fixturesPath.'/dumper/url_matcher1.php', $dumper->dump(), '->dump() dumps basic routes to the correct PHP file.');
|
||||
}
|
||||
|
Reference in New Issue
Block a user