Adding JsonResponseHandler to Phalcon provider

This commit is contained in:
Tim Robertson
2013-09-24 18:22:35 -04:00
parent aa782a8174
commit fb366ae22f
@@ -8,6 +8,7 @@ namespace Whoops\Provider\Phalcon;
use Whoops\Run;
use Whoops\Handler\PrettyPageHandler;
use Whoops\Handler\JsonResponseHandler;
use Phalcon\DI;
use Phalcon\DI\Exception;
@@ -23,10 +24,17 @@ class WhoopsServiceProvider
}
// There's only ever going to be one error page...right?
$di->setShared('whoops.error_page_handler', function() {
$di->setShared('whoops.pretty_page_handler', function() {
return new PrettyPageHandler;
});
// There's only ever going to be one error page...right?
$di->setShared('whoops.json_response_handler', function() {
$jsonHandler = new JsonResponseHandler;
$jsonHandler->onlyForAjaxRequests(true);
return $jsonHandler;
});
// Retrieves info on the Phalcon environment and ships it off
// to the PrettyPageHandler's data tables:
// This works by adding a new handler to the stack that runs
@@ -42,7 +50,7 @@ class WhoopsServiceProvider
}
// Request info:
$di['whoops.error_page_handler']->addDataTable('Phalcon Application (Request)', array(
$di['whoops.pretty_page_handler']->addDataTable('Phalcon Application (Request)', array(
'URI' => $request->getScheme().'://'.$request->getServer('HTTP_HOST').$request->getServer('REQUEST_URI'),
'Request URI' => $request->getServer('REQUEST_URI'),
'Path Info' => $request->getServer('PATH_INFO'),
@@ -59,8 +67,9 @@ class WhoopsServiceProvider
$di->setShared('whoops', function() use($di, $phalcon_info_handler) {
$run = new Run;
$run->pushHandler($di['whoops.error_page_handler']);
$run->pushHandler($di['whoops.pretty_page_handler']);
$run->pushHandler($phalcon_info_handler);
$run->pushHandler($di['whoops.json_response_handler']);
return $run;
});