Commit f99f6ef7 authored by Fabien Potencier's avatar Fabien Potencier

added a way to set default values for route variables

parent 745ca252
...@@ -82,6 +82,19 @@ class Controller ...@@ -82,6 +82,19 @@ class Controller
return $this; return $this;
} }
/**
* Sets the default value for a route variable.
*
* @param string $variable The variable name
* @param mixed $default The default value
*/
public function value($variable, $default)
{
$this->route->setDefault($variable, $default);
return $this;
}
/** /**
* Freezes the controller. * Freezes the controller.
* *
......
...@@ -51,6 +51,15 @@ class ControllerTest extends \PHPUnit_Framework_TestCase ...@@ -51,6 +51,15 @@ class ControllerTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(array('bar' => '\d+'), $controller->getRoute()->getRequirements()); $this->assertEquals(array('bar' => '\d+'), $controller->getRoute()->getRequirements());
} }
public function testValue()
{
$controller = new Controller(new Route('/foo/{bar}'));
$ret = $controller->value('bar', 'foo');
$this->assertSame($ret, $controller);
$this->assertEquals(array('bar' => 'foo'), $controller->getRoute()->getDefaults());
}
/** /**
* @dataProvider provideRouteAndExpectedRouteName * @dataProvider provideRouteAndExpectedRouteName
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment