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
d2b59062
Commit
d2b59062
authored
Jan 07, 2015
by
Nils Adermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow global after middlewares to return responses like route specific ones
parent
f64ac7b8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
1 deletion
+20
-1
src/Silex/Application.php
src/Silex/Application.php
+6
-1
tests/Silex/Tests/MiddlewareTest.php
tests/Silex/Tests/MiddlewareTest.php
+14
-0
No files found.
src/Silex/Application.php
View file @
d2b59062
...
...
@@ -339,7 +339,12 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte
return
;
}
call_user_func
(
$app
[
'callback_resolver'
]
->
resolveCallback
(
$callback
),
$event
->
getRequest
(),
$event
->
getResponse
(),
$app
);
$response
=
call_user_func
(
$app
[
'callback_resolver'
]
->
resolveCallback
(
$callback
),
$event
->
getRequest
(),
$event
->
getResponse
(),
$app
);
if
(
$response
instanceof
Response
)
{
$event
->
setResponse
(
$response
);
}
elseif
(
null
!==
$response
)
{
throw
new
\RuntimeException
(
'An after middleware returned an invalid response value. Must return null or an instance of Response.'
);
}
},
$priority
);
}
...
...
tests/Silex/Tests/MiddlewareTest.php
View file @
d2b59062
...
...
@@ -234,6 +234,20 @@ class MiddlewareTest extends \PHPUnit_Framework_TestCase
$this
->
assertEquals
(
'foo---'
,
$app
->
handle
(
$request
)
->
getContent
());
}
public
function
testAfterFilterCanReturnResponse
()
{
$app
=
new
Application
();
$app
->
after
(
function
(
Request
$request
,
Response
$response
)
{
return
new
Response
(
'bar'
);
});
$app
->
match
(
'/'
,
function
()
{
return
new
Response
(
'foo'
);
});
$request
=
Request
::
create
(
'/'
);
$this
->
assertEquals
(
'bar'
,
$app
->
handle
(
$request
)
->
getContent
());
}
public
function
testRouteAndApplicationMiddlewareParameterInjection
()
{
$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