Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
Silex
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
Silex
Commits
f99f6ef7
Commit
f99f6ef7
authored
Apr 16, 2011
by
Fabien Potencier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added a way to set default values for route variables
parent
745ca252
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
0 deletions
+22
-0
src/Silex/Controller.php
src/Silex/Controller.php
+13
-0
tests/Silex/Tests/ControllerTest.php
tests/Silex/Tests/ControllerTest.php
+9
-0
No files found.
src/Silex/Controller.php
View file @
f99f6ef7
...
...
@@ -82,6 +82,19 @@ class Controller
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.
*
...
...
tests/Silex/Tests/ControllerTest.php
View file @
f99f6ef7
...
...
@@ -51,6 +51,15 @@ class ControllerTest extends \PHPUnit_Framework_TestCase
$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
*/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment