8000 [Routing] fixed several bugs and applied improvements by Tobion · Pull Request #3754 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix that Route::compile needs to recompile once route is modified
  • Loading branch information
Tobion committed Apr 11, 2012
commit a4a3f4476f53336d22dc7ac2d17fecad8c3ac850
10 changes: 9 additions & 1 deletion src/Symfony/Component/Routing/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,12 @@ public function setPattern($pattern)
$this->pattern = trim($pattern);

// a route must start with a slash
if (empty($this->pattern) || '/' !== $this->pattern[0]) {
if ('' === $this->pattern || '/' !== $this->pattern[0]) {
$this->pattern = '/'.$this->pattern;
}

$this->compiled = null;

return $this;
}

Expand Down Expand Up @@ -128,6 +130,7 @@ public function addOptions(array $options)
foreach ($options as $name => $option) {
$this->options[(string) $name] = $option;
}
$this->compiled = null;

return $this;
}
Expand All @@ -147,6 +150,7 @@ public function addOptions(array $options)
public function setOption($name, $value)
{
$this->options[$name] = $value;
$this->compiled = null;

return $this;
}
Expand Down Expand Up @@ -203,6 +207,7 @@ public function addDefaults(array $defaults)
foreach ($defaults as $name => $default) {
$this->defaults[(string) $name] = $default;
}
$this->compiled = null;

return $this;
}
Expand Down Expand Up @@ -244,6 +249,7 @@ public function hasDefault($name)
public function setDefault($name, $default)
{
$this->defaults[(string) $name] = $default;
$this->compiled = null;

return $this;
}
Expand Down Expand Up @@ -288,6 +294,7 @@ public function addRequirements(array $requirements)
foreach ($requirements as $key => $regex) {
$this->requirements[$key] = $this->sanitizeRequirement($key, $regex);
}
$this->compiled = null;

return $this;
}
Expand Down Expand Up @@ -317,6 +324,7 @@ public function getRequirement($key)
public function setRequirement($key, $regex)
{
$this->requirements[$key] = $this->sanitizeRequirement($key, $regex);
$this->compiled = null;

return $this;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Symfony/Component/Routing/Tests/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ public function getInvalidRequirements()
public function testCompile()
{
$route = new Route('/{foo}');
$this->assertEquals('Symfony\\Component\\Routing\\CompiledRoute', get_class($compiled = $route->compile()), '->compile() returns a compiled route');
$this->assertEquals($compiled, $route->compile(), '->compile() only compiled the route once');
$this->assertInstanceOf('Symfony\Component\Routing\CompiledRoute', $compiled = $route->compile(), '->compile() returns a compiled route');
$this->assertSame($compiled, $route->compile(), '->compile() only compiled the route once if unchanged');
$route->setRequirement('foo', '.*');
$this->assertNotSame($compiled, $route->compile(), '->compile() recompiles if the route was modified');
}
}
0