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
262fd9a0
Commit
262fd9a0
authored
Aug 24, 2011
by
Fabien Potencier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added Symfony2 ResponseListener registration
parent
a46df6a3
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
0 deletions
+21
-0
src/Silex/Application.php
src/Silex/Application.php
+2
-0
tests/Silex/Tests/ApplicationTest.php
tests/Silex/Tests/ApplicationTest.php
+19
-0
No files found.
src/Silex/Application.php
View file @
262fd9a0
...
@@ -19,6 +19,7 @@ use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
...
@@ -19,6 +19,7 @@ use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use
Symfony\Component\HttpKernel\Event\FilterControllerEvent
;
use
Symfony\Component\HttpKernel\Event\FilterControllerEvent
;
use
Symfony\Component\HttpKernel\Event\FilterResponseEvent
;
use
Symfony\Component\HttpKernel\Event\FilterResponseEvent
;
use
Symfony\Component\HttpKernel\Event\GetResponseEvent
;
use
Symfony\Component\HttpKernel\Event\GetResponseEvent
;
use
Symfony\Component\HttpKernel\EventListener\ResponseListener
;
use
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
;
use
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
;
use
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
;
use
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
;
use
Symfony\Component\HttpKernel\Exception\HttpExceptionInterface
;
use
Symfony\Component\HttpKernel\Exception\HttpExceptionInterface
;
...
@@ -81,6 +82,7 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
...
@@ -81,6 +82,7 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
if
(
isset
(
$app
[
'exception_handler'
]))
{
if
(
isset
(
$app
[
'exception_handler'
]))
{
$dispatcher
->
addSubscriber
(
$app
[
'exception_handler'
]);
$dispatcher
->
addSubscriber
(
$app
[
'exception_handler'
]);
}
}
$dispatcher
->
addListener
(
KernelEvents
::
RESPONSE
,
array
(
new
ResponseListener
(
$app
[
'charset'
]),
'onKernelResponse'
));
return
$dispatcher
;
return
$dispatcher
;
});
});
...
...
tests/Silex/Tests/ApplicationTest.php
View file @
262fd9a0
...
@@ -146,6 +146,25 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
...
@@ -146,6 +146,25 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$this
->
assertEquals
(
'Hello Fabien'
,
$app
->
handle
(
Request
::
create
(
'/Fabien'
))
->
getContent
());
$this
->
assertEquals
(
'Hello Fabien'
,
$app
->
handle
(
Request
::
create
(
'/Fabien'
))
->
getContent
());
}
}
public
function
testHttpSpec
()
{
$app
=
new
Application
();
$app
[
'charset'
]
=
'ISO-8859-1'
;
$app
->
get
(
'/'
,
function
()
{
return
'hello'
;
});
// content is empty for HEAD requests
$response
=
$app
->
handle
(
Request
::
create
(
'/'
,
'HEAD'
));
$this
->
assertEquals
(
''
,
$response
->
getContent
());
// charset is appended to Content-Type
$response
=
$app
->
handle
(
Request
::
create
(
'/'
));
$response
->
prepare
();
$this
->
assertEquals
(
'text/html; charset=ISO-8859-1'
,
$response
->
headers
->
get
(
'Content-Type'
));
}
}
}
class
FooController
class
FooController
...
...
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