Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Speed up url matching for route without variable

  • Loading branch information...
commit 5e948076687091b44e8f5b11ed1f3213e8211e81 1 parent 98db58a
Victor Berchet vicb authored fabpot committed
18 src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php
@@ -60,17 +60,25 @@ protected function addMatcher()
60 60 $conditions[] = sprintf("isset(\$this->context['method']) && preg_match('#^(%s)$#xi', \$this->context['method'])", $req);
61 61 }
62 62
63   - if ($compiledRoute->getStaticPrefix()) {
64   - $conditions[] = sprintf("0 === strpos(\$url, '%s')", $compiledRoute->getStaticPrefix());
65   - }
  63 + if (!count($compiledRoute->getVariables()) && false !== preg_match('#^(.)\^(?P<url>.*?)\$\1#', $compiledRoute->getRegex(), $m)) {
  64 + $conditions[] = sprintf("\$url === '%s'", $m['url']);
  65 +
  66 + $matches = 'array()';
  67 + } else {
  68 + if ($compiledRoute->getStaticPrefix()) {
  69 + $conditions[] = sprintf("0 === strpos(\$url, '%s')", $compiledRoute->getStaticPrefix());
  70 + }
66 71
67   - $conditions[] = sprintf("preg_match('%s', \$url, \$matches)", $compiledRoute->getRegex());
  72 + $conditions[] = sprintf("preg_match('%s', \$url, \$matches)", $compiledRoute->getRegex());
  73 +
  74 + $matches = '$matches';
  75 + }
68 76
69 77 $conditions = implode(' && ', $conditions);
70 78
71 79 $code[] = sprintf(<<<EOF
72 80 if ($conditions) {
73   - return array_merge(\$this->mergeDefaults(\$matches, %s), array('_route' => '%s'));
  81 + return array_merge(\$this->mergeDefaults($matches, %s), array('_route' => '%s'));
74 82 }
75 83
76 84 EOF
4 tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher1.php
@@ -29,6 +29,10 @@ public function match($url)
29 29 return array_merge($this->mergeDefaults($matches, array ()), array('_route' => 'bar'));
30 30 }
31 31
  32 + if ($url === '/test/baz') {
  33 + return array_merge($this->mergeDefaults(array(), array ()), array('_route' => 'baz'));
  34 + }
  35 +
32 36 return false;
33 37 }
34 38 }
4 tests/Symfony/Tests/Component/Routing/Matcher/Dumper/PhpMatcherDumperTest.php
@@ -38,6 +38,10 @@ public function testDump()
38 38 array(),
39 39 array('_method' => 'GET|head')
40 40 ));
  41 + $collection->add('baz', new Route(
  42 + '/test/baz'
  43 + ));
  44 +
41 45 $dumper = new PhpMatcherDumper($collection);
42 46 $this->assertStringEqualsFile(self::$fixturesPath.'/dumper/url_matcher1.php', $dumper->dump(), '->dump() dumps basic routes to the correct PHP file.');
43 47 }

0 comments on commit 5e94807

Please sign in to comment.
Something went wrong with that request. Please try again.