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
9c68da8d
Commit
9c68da8d
authored
Oct 13, 2013
by
Fabien Potencier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changed the default controller to be unique for the whole app
parent
2b966973
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
21 deletions
+19
-21
src/Silex/ControllerCollection.php
src/Silex/ControllerCollection.php
+6
-7
tests/Silex/Tests/ApplicationTest.php
tests/Silex/Tests/ApplicationTest.php
+12
-0
tests/Silex/Tests/ControllerCollectionTest.php
tests/Silex/Tests/ControllerCollectionTest.php
+0
-13
tests/Silex/Tests/Provider/RememberMeServiceProviderTest.php
tests/Silex/Tests/Provider/RememberMeServiceProviderTest.php
+1
-1
No files found.
src/Silex/ControllerCollection.php
View file @
9c68da8d
...
...
@@ -12,6 +12,7 @@
namespace
Silex
;
use
Symfony\Component\Routing\RouteCollection
;
use
Symfony\Component\HttpFoundation\Request
;
use
Silex\Controller
;
/**
...
...
@@ -28,6 +29,7 @@ class ControllerCollection
{
protected
$controllers
=
array
();
protected
$defaultRoute
;
protected
$defaultController
;
/**
* Constructor.
...
...
@@ -35,6 +37,9 @@ class ControllerCollection
public
function
__construct
(
Route
$defaultRoute
)
{
$this
->
defaultRoute
=
$defaultRoute
;
$this
->
defaultController
=
function
(
Request
$request
)
{
throw
new
\LogicException
(
sprintf
(
'The "%s" route must have code to run when it matches.'
,
$request
->
attributes
->
get
(
'_route'
)));
};
}
/**
...
...
@@ -52,13 +57,7 @@ class ControllerCollection
$route
=
clone
$this
->
defaultRoute
;
$route
->
setPath
(
$pattern
);
$this
->
controllers
[]
=
$controller
=
new
Controller
(
$route
);
if
(
null
===
$to
)
{
$to
=
function
()
use
(
$controller
)
{
throw
new
\LogicException
(
sprintf
(
'The "%s" route must have code to run when it matches.'
,
$controller
->
getRouteName
()));
};
}
$route
->
setDefault
(
'_controller'
,
$to
);
$route
->
setDefault
(
'_controller'
,
null
===
$to
?
$this
->
defaultController
:
$to
);
return
$controller
;
}
...
...
tests/Silex/Tests/ApplicationTest.php
View file @
9c68da8d
...
...
@@ -502,6 +502,18 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
}
}
/**
* @expectedException \LogicException
* @expectedExceptionMessage The "homepage" route must have code to run when it matches.
*/
public
function
testGetRouteCollectionWithRouteWithoutController
()
{
$app
=
new
Application
();
$app
[
'exception_handler'
]
->
disable
();
$app
->
match
(
'/'
)
->
bind
(
'homepage'
);
$app
->
handle
(
Request
::
create
(
'/'
));
}
public
function
testRedirectDoesNotRaisePHPNoticesWhenMonologIsRegistered
()
{
$app
=
new
Application
();
...
...
tests/Silex/Tests/ControllerCollectionTest.php
View file @
9c68da8d
...
...
@@ -30,19 +30,6 @@ class ControllerCollectionTest extends \PHPUnit_Framework_TestCase
$this
->
assertEquals
(
0
,
count
(
$routes
->
all
()));
}
/**
* @expectedException \LogicException
* @expectedExceptionMessage The "foo" route must have code to run when it matches.
*/
public
function
testGetRouteCollectionWithRouteWithoutController
()
{
$controllers
=
new
ControllerCollection
(
new
Route
());
$controllers
->
match
(
'/foo'
)
->
bind
(
'foo'
);
$routes
=
$controllers
->
flush
();
call_user_func
(
$routes
->
get
(
'foo'
)
->
getDefault
(
'_controller'
));
}
public
function
testGetRouteCollectionWithRoutes
()
{
$controllers
=
new
ControllerCollection
(
new
Route
());
...
...
tests/Silex/Tests/Provider/RememberMeServiceProviderTest.php
View file @
9c68da8d
...
...
@@ -55,7 +55,7 @@ class RememberMeServiceProviderTest extends WebTestCase
$app
=
new
Application
();
$app
[
'debug'
]
=
true
;
unset
(
$app
[
'exception_handler'
]
);
$app
[
'exception_handler'
]
->
disable
(
);
$app
->
register
(
new
SessionServiceProvider
(),
array
(
'session.test'
=>
true
,
...
...
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