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
c89133e8
Commit
c89133e8
authored
Jun 15, 2012
by
Fabien Potencier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplified some code
parent
d89cbcd9
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
7 additions
and
74 deletions
+7
-74
src/Silex/Application.php
src/Silex/Application.php
+5
-5
src/Silex/ExceptionHandler.php
src/Silex/ExceptionHandler.php
+2
-1
src/Silex/GetResponseForErrorEvent.php
src/Silex/GetResponseForErrorEvent.php
+0
-30
src/Silex/StringResponseConverter.php
src/Silex/StringResponseConverter.php
+0
-38
No files found.
src/Silex/Application.php
View file @
c89133e8
...
...
@@ -345,7 +345,7 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
*/
public
function
error
(
$callback
,
$priority
=
0
)
{
$this
[
'dispatcher'
]
->
addListener
(
SilexEvents
::
ERROR
,
function
(
GetResponseForE
rror
Event
$event
)
use
(
$callback
)
{
$this
[
'dispatcher'
]
->
addListener
(
SilexEvents
::
ERROR
,
function
(
GetResponseForE
xception
Event
$event
)
use
(
$callback
)
{
$exception
=
$event
->
getException
();
if
(
is_array
(
$callback
))
{
...
...
@@ -370,7 +370,7 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
$result
=
call_user_func
(
$callback
,
$exception
,
$code
);
if
(
null
!==
$result
)
{
$event
->
set
StringResponse
(
$result
);
$event
->
set
Response
(
$result
instanceof
Response
?
$result
:
new
Response
((
string
)
$result
)
);
}
},
$priority
);
}
...
...
@@ -567,8 +567,8 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
public
function
onKernelView
(
GetResponseForControllerResultEvent
$event
)
{
$response
=
$event
->
getControllerResult
();
$converter
=
new
StringResponseConverter
();
$event
->
setResponse
(
$
converter
->
convert
(
$response
));
$event
->
setResponse
(
$
response
instanceof
Response
?
$response
:
new
Response
((
string
)
$response
));
}
/**
...
...
@@ -621,7 +621,7 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
}
}
$errorEvent
=
new
GetResponseForE
rror
Event
(
$this
,
$event
->
getRequest
(),
$event
->
getRequestType
(),
$event
->
getException
());
$errorEvent
=
new
GetResponseForE
xception
Event
(
$this
,
$event
->
getRequest
(),
$event
->
getRequestType
(),
$event
->
getException
());
$this
[
'dispatcher'
]
->
dispatch
(
SilexEvents
::
ERROR
,
$errorEvent
);
if
(
$errorEvent
->
hasResponse
())
{
...
...
src/Silex/ExceptionHandler.php
View file @
c89133e8
...
...
@@ -13,6 +13,7 @@ namespace Silex;
use
Symfony\Component\HttpKernel\Debug\ExceptionHandler
as
DebugExceptionHandler
;
use
Symfony\Component\EventDispatcher\EventSubscriberInterface
;
use
Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent
;
/**
* Defaults exception handler.
...
...
@@ -21,7 +22,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
*/
class
ExceptionHandler
implements
EventSubscriberInterface
{
public
function
onSilexError
(
GetResponseForE
rror
Event
$event
)
public
function
onSilexError
(
GetResponseForE
xception
Event
$event
)
{
$app
=
$event
->
getKernel
();
$handler
=
new
DebugExceptionHandler
(
$app
[
'debug'
]);
...
...
src/Silex/GetResponseForErrorEvent.php
deleted
100644 → 0
View file @
d89cbcd9
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace
Silex
;
use
Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent
;
/**
* GetResponseForExceptionEvent with additional setStringResponse method
*
* setStringResponse will convert strings to response objects.
*
* @author Igor Wiedler <igor@wiedler.ch>
*/
class
GetResponseForErrorEvent
extends
GetResponseForExceptionEvent
{
public
function
setStringResponse
(
$response
)
{
$converter
=
new
StringResponseConverter
();
$this
->
setResponse
(
$converter
->
convert
(
$response
));
}
}
src/Silex/StringResponseConverter.php
deleted
100644 → 0
View file @
d89cbcd9
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace
Silex
;
use
Symfony\Component\HttpFoundation\Response
;
/**
* Converts string responses to Response objects.
*
* @author Igor Wiedler <igor@wiedler.ch>
*/
class
StringResponseConverter
{
/**
* Does the conversion
*
* @param string $response The response string
*
* @return Response A Response object
*/
public
function
convert
(
$response
)
{
if
(
!
$response
instanceof
Response
)
{
return
new
Response
((
string
)
$response
);
}
return
$response
;
}
}
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