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
4e6031e2
Commit
4e6031e2
authored
Oct 19, 2013
by
Fabien Potencier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed order of route registration for mounted controllers
parent
bc673b47
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
9 deletions
+44
-9
doc/changelog.rst
doc/changelog.rst
+1
-0
src/Silex/Application.php
src/Silex/Application.php
+1
-1
src/Silex/ControllerCollection.php
src/Silex/ControllerCollection.php
+28
-8
tests/Silex/Tests/ApplicationTest.php
tests/Silex/Tests/ApplicationTest.php
+14
-0
No files found.
doc/changelog.rst
View file @
4e6031e2
...
@@ -4,6 +4,7 @@ Changelog
...
@@ -4,6 +4,7 @@ Changelog
1.2.0 (2013-XX-XX)
1.2.0 (2013-XX-XX)
------------------
------------------
* [BC BREAK] Routes are now always added in the order of their registration (even for mounted routes)
* Added run() on Route to be able to define the controller code
* Added run() on Route to be able to define the controller code
* Deprecated TwigCoreExtension (register the new HttpFragmentServiceProvider instead)
* Deprecated TwigCoreExtension (register the new HttpFragmentServiceProvider instead)
* Added HttpFragmentServiceProvider
* Added HttpFragmentServiceProvider
...
...
src/Silex/Application.php
View file @
4e6031e2
...
@@ -473,7 +473,7 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte
...
@@ -473,7 +473,7 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte
throw
new
\LogicException
(
'The "mount" method takes either a ControllerCollection or a ControllerProviderInterface instance.'
);
throw
new
\LogicException
(
'The "mount" method takes either a ControllerCollection or a ControllerProviderInterface instance.'
);
}
}
$this
[
'
routes'
]
->
addCollection
(
$controllers
->
flush
(
$prefix
)
);
$this
[
'
controllers'
]
->
mount
(
$prefix
,
$controllers
);
return
$this
;
return
$this
;
}
}
...
...
src/Silex/ControllerCollection.php
View file @
4e6031e2
...
@@ -30,6 +30,7 @@ class ControllerCollection
...
@@ -30,6 +30,7 @@ class ControllerCollection
protected
$controllers
=
array
();
protected
$controllers
=
array
();
protected
$defaultRoute
;
protected
$defaultRoute
;
protected
$defaultController
;
protected
$defaultController
;
protected
$prefix
;
/**
/**
* Constructor.
* Constructor.
...
@@ -42,6 +43,19 @@ class ControllerCollection
...
@@ -42,6 +43,19 @@ class ControllerCollection
};
};
}
}
/**
* Mounts controllers under the given route prefix.
*
* @param string $prefix The route prefix
* @param ControllerCollection $controllers A ControllerCollection instance
*/
public
function
mount
(
$prefix
,
ControllerCollection
$controllers
)
{
$controllers
->
prefix
=
$prefix
;
$this
->
controllers
[]
=
$controllers
;
}
/**
/**
* Maps a pattern to a callable.
* Maps a pattern to a callable.
*
*
...
@@ -123,7 +137,9 @@ class ControllerCollection
...
@@ -123,7 +137,9 @@ class ControllerCollection
call_user_func_array
(
array
(
$this
->
defaultRoute
,
$method
),
$arguments
);
call_user_func_array
(
array
(
$this
->
defaultRoute
,
$method
),
$arguments
);
foreach
(
$this
->
controllers
as
$controller
)
{
foreach
(
$this
->
controllers
as
$controller
)
{
call_user_func_array
(
array
(
$controller
,
$method
),
$arguments
);
if
(
$controller
instanceof
Controller
)
{
call_user_func_array
(
array
(
$controller
,
$method
),
$arguments
);
}
}
}
return
$this
;
return
$this
;
...
@@ -141,15 +157,19 @@ class ControllerCollection
...
@@ -141,15 +157,19 @@ class ControllerCollection
$routes
=
new
RouteCollection
();
$routes
=
new
RouteCollection
();
foreach
(
$this
->
controllers
as
$controller
)
{
foreach
(
$this
->
controllers
as
$controller
)
{
if
(
!
$name
=
$controller
->
getRouteName
())
{
if
(
$controller
instanceof
Controller
)
{
$name
=
$controller
->
generateRouteName
(
$prefix
);
if
(
!
$name
=
$controller
->
getRouteName
())
{
while
(
$routes
->
get
(
$name
))
{
$name
=
$controller
->
generateRouteName
(
$prefix
);
$name
.=
'_'
;
while
(
$routes
->
get
(
$name
))
{
$name
.=
'_'
;
}
$controller
->
bind
(
$name
);
}
}
$controller
->
bind
(
$name
);
$routes
->
add
(
$name
,
$controller
->
getRoute
());
$controller
->
freeze
();
}
else
{
$routes
->
addCollection
(
$controller
->
flush
(
$controller
->
prefix
));
}
}
$routes
->
add
(
$name
,
$controller
->
getRoute
());
$controller
->
freeze
();
}
}
$routes
->
addPrefix
(
$prefix
);
$routes
->
addPrefix
(
$prefix
);
...
...
tests/Silex/Tests/ApplicationTest.php
View file @
4e6031e2
...
@@ -489,6 +489,20 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
...
@@ -489,6 +489,20 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$this
->
assertSame
(
$app
,
$app
->
mount
(
'/hello'
,
$mounted
));
$this
->
assertSame
(
$app
,
$app
->
mount
(
'/hello'
,
$mounted
));
}
}
public
function
testMountPreservesOrder
()
{
$app
=
new
Application
();
$mounted
=
new
ControllerCollection
(
new
Route
());
$mounted
->
get
(
'/mounted'
)
->
bind
(
'second'
);
$app
->
get
(
'/before'
)
->
bind
(
'first'
);
$app
->
mount
(
'/'
,
$mounted
);
$app
->
get
(
'/after'
)
->
bind
(
'third'
);
$app
->
flush
();
$this
->
assertEquals
(
array
(
'first'
,
'second'
,
'third'
),
array_keys
(
iterator_to_array
(
$app
[
'routes'
])));
}
public
function
testSendFile
()
public
function
testSendFile
()
{
{
$app
=
new
Application
();
$app
=
new
Application
();
...
...
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