Skip to content

Commit

Permalink
add errorhandler
Browse files Browse the repository at this point in the history
  • Loading branch information
mamuz committed Aug 17, 2015
1 parent f4a22b9 commit 9b86aed
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion config/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
],
],
'services' => [
'logger' => 'PhalconSkeleton\Application\Service\Logger',
'logger' => 'PhalconSkeleton\Application\Service\Logger',
'errorhandler' => 'PhalconSkeleton\Application\Service\ErrorHandler',
],
'loggers' => [
'file' => [
Expand Down
11 changes: 6 additions & 5 deletions src/Application/Service/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@
namespace Phpg\Application\Service;

use Phalcon\Di;
use Phalcon\Dispatcher as PhalconDispatcher;
use Phalcon\Dispatcher;
use Phalcon\Events\Event;
use Phalcon\Mvc;
use Phapp\Application\Service\InjectableInterface;

class Dispatcher implements InjectableInterface
class ErrorHandler implements InjectableInterface
{
public static function injectTo(Di $di)
{
/** @var \Phalcon\Mvc\Dispatcher $dispatcher */
/** @var Dispatcher $dispatcher */
$dispatcher = $di->getShared('dispatcher');
$dispatcher->getEventsManager()->attach(
'dispatch:beforeException',
function (Event $event, PhalconDispatcher $dispatcher, \Exception $e) {
function (Event $event, Dispatcher $dispatcher, \Exception $e) {
/** @var \Phalcon\Logger\AdapterInterface $logger */
$logger = $dispatcher->getDI()->get('logger');
$logger->error($e->getMessage());
if ($dispatcher instanceof \Phalcon\Mvc\Dispatcher) {
if ($dispatcher instanceof Mvc\Dispatcher) {
if ($e instanceof Mvc\Dispatcher\Exception) {
$action = 'notFound';
} else {
Expand Down

0 comments on commit 9b86aed

Please sign in to comment.