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
a0274403
Commit
a0274403
authored
Jul 22, 2011
by
Fabien Potencier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplified the error handler as most of the code has now been migrated to Symfony directly
parent
4091be76
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
20 deletions
+6
-20
src/Silex/ExceptionHandler.php
src/Silex/ExceptionHandler.php
+2
-17
tests/Silex/Tests/ErrorHandlerTest.php
tests/Silex/Tests/ErrorHandlerTest.php
+3
-2
vendor/Symfony/Component/HttpKernel
vendor/Symfony/Component/HttpKernel
+1
-1
No files found.
src/Silex/ExceptionHandler.php
View file @
a0274403
...
...
@@ -13,7 +13,6 @@ namespace Silex;
use
Silex\Application
;
use
Symfony\Component\HttpFoundation\Response
;
use
Symfony\Component\HttpKernel\Exception\HttpExceptionInterface
;
use
Symfony\Component\HttpKernel\Debug\ExceptionHandler
as
DebugExceptionHandler
;
use
Symfony\Component\EventDispatcher\EventSubscriberInterface
;
...
...
@@ -27,23 +26,9 @@ class ExceptionHandler implements EventSubscriberInterface
public
function
onSilexError
(
GetResponseForErrorEvent
$event
)
{
$app
=
$event
->
getKernel
();
$exception
=
$event
->
getException
();
$code
=
$exception
instanceof
HttpExceptionInterface
?
$exception
->
getStatusCode
()
:
500
;
$handler
=
new
DebugExceptionHandler
(
$app
[
'debug'
]);
if
(
$app
[
'debug'
])
{
$handler
=
new
DebugExceptionHandler
();
$response
=
new
Response
(
$handler
->
getErrorMessage
(
$exception
),
$code
);
}
else
{
$title
=
'Whoops, looks like something went wrong.'
;
if
(
404
==
$code
)
{
$title
=
'Sorry, the page you are looking for could not be found.'
;
}
$response
=
new
Response
(
sprintf
(
'<!DOCTYPE html><html><head><meta charset="utf-8"><title>%s</title></head><body><h1>%s</h1></body></html>'
,
$title
,
$title
),
$code
);
}
$event
->
setResponse
(
$response
);
$event
->
setResponse
(
$handler
->
createResponse
(
$event
->
getException
()));
}
/**
...
...
tests/Silex/Tests/ErrorHandlerTest.php
View file @
a0274403
...
...
@@ -50,7 +50,8 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
$request
=
Request
::
create
(
'/foo'
);
$response
=
$app
->
handle
(
$request
);
$this
->
assertContains
(
'<title>foo exception (500 Internal Server Error)</title>'
,
$response
->
getContent
());
$this
->
assertContains
(
'foo exception'
,
$response
->
getContent
());
$this
->
assertEquals
(
500
,
$response
->
getStatusCode
());
}
...
...
@@ -72,7 +73,7 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
$request
=
Request
::
create
(
'/foo'
);
$response
=
$app
->
handle
(
$request
);
$this
->
assertContains
(
'
<title>No route found for "GET /foo" (500 Internal Server Error)</title>
'
,
$response
->
getContent
());
$this
->
assertContains
(
'
No route found for "GET /foo"
'
,
$response
->
getContent
());
$this
->
assertEquals
(
404
,
$response
->
getStatusCode
());
}
...
...
HttpKernel
@
14b5f938
Subproject commit
3a0562757737c0d640b5f7c69efe2fbbaebd4a7c
Subproject commit
14b5f9385023567b59b8f227fc463968a3426a13
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