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
c959ea3f
Commit
c959ea3f
authored
May 20, 2012
by
Fabien Potencier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ensured that generated route names are unique (closes #215)
parent
397190d3
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
7 deletions
+23
-7
src/Silex/Controller.php
src/Silex/Controller.php
+2
-2
src/Silex/ControllerCollection.php
src/Silex/ControllerCollection.php
+7
-3
tests/Silex/Tests/ControllerCollectionTest.php
tests/Silex/Tests/ControllerCollectionTest.php
+13
-1
tests/Silex/Tests/ControllerTest.php
tests/Silex/Tests/ControllerTest.php
+1
-1
No files found.
src/Silex/Controller.php
View file @
c959ea3f
...
...
@@ -185,7 +185,7 @@ class Controller
$this
->
isFrozen
=
true
;
}
public
function
bindDefault
RouteName
(
$prefix
)
public
function
generate
RouteName
(
$prefix
)
{
$requirements
=
$this
->
route
->
getRequirements
();
$method
=
isset
(
$requirements
[
'_method'
])
?
$requirements
[
'_method'
]
:
''
;
...
...
@@ -194,6 +194,6 @@ class Controller
$routeName
=
str_replace
(
array
(
'/'
,
':'
,
'|'
,
'-'
),
'_'
,
$routeName
);
$routeName
=
preg_replace
(
'/[^a-z0-9A-Z_.]+/'
,
''
,
$routeName
);
$this
->
routeName
=
$routeName
;
return
$routeName
;
}
}
src/Silex/ControllerCollection.php
View file @
c959ea3f
...
...
@@ -120,10 +120,14 @@ class ControllerCollection
$routes
=
new
RouteCollection
();
foreach
(
$this
->
controllers
as
$controller
)
{
if
(
!
$controller
->
getRouteName
())
{
$controller
->
bindDefaultRouteName
(
$prefix
);
if
(
!
$name
=
$controller
->
getRouteName
())
{
$name
=
$controller
->
generateRouteName
(
$prefix
);
while
(
$routes
->
get
(
$name
))
{
$name
.=
'_'
;
}
$routes
->
add
(
$controller
->
getRouteName
(),
$controller
->
getRoute
());
$controller
->
bind
(
$name
);
}
$routes
->
add
(
$name
,
$controller
->
getRoute
());
$controller
->
freeze
();
}
...
...
tests/Silex/Tests/ControllerCollectionTest.php
View file @
c959ea3f
...
...
@@ -76,10 +76,22 @@ class ControllerCollectionTest extends \PHPUnit_Framework_TestCase
$controllers
->
add
(
$mountedRootController
);
$mainRootController
=
new
Controller
(
new
Route
(
'/'
));
$mainRootController
->
bind
DefaultRouteName
(
'main_'
);
$mainRootController
->
bind
(
$mainRootController
->
generateRouteName
(
'main_'
)
);
$controllers
->
flush
();
$this
->
assertNotEquals
(
$mainRootController
->
getRouteName
(),
$mountedRootController
->
getRouteName
());
}
public
function
testUniqueGeneratedRouteNames
()
{
$controllers
=
new
ControllerCollection
();
$controllers
->
add
(
new
Controller
(
new
Route
(
'/a-a'
)));
$controllers
->
add
(
new
Controller
(
new
Route
(
'/a_a'
)));
$routes
=
$controllers
->
flush
();
$this
->
assertCount
(
2
,
$routes
->
all
());
$this
->
assertEquals
(
array
(
'_a_a'
,
'_a_a_'
),
array_keys
(
$routes
->
all
()));
}
}
tests/Silex/Tests/ControllerTest.php
View file @
c959ea3f
...
...
@@ -75,7 +75,7 @@ class ControllerTest extends \PHPUnit_Framework_TestCase
public
function
testDefaultRouteNameGeneration
(
Route
$route
,
$expectedRouteName
)
{
$controller
=
new
Controller
(
$route
);
$controller
->
bind
DefaultRouteName
(
''
);
$controller
->
bind
(
$controller
->
generateRouteName
(
''
)
);
$this
->
assertEquals
(
$expectedRouteName
,
$controller
->
getRouteName
());
}
...
...
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