Skip to content

Commit

Permalink
Remove SDK exception & error handler. #296
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Feb 22, 2016
1 parent c071099 commit d5c98b8
Showing 1 changed file with 0 additions and 69 deletions.
69 changes: 0 additions & 69 deletions src/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,6 @@ class Application extends Container
ServiceProviders\BroadcastServiceProvider::class,
];

/**
* The exception handler.
*
* @var callable
*/
protected $exceptionHandler;

/**
* Application constructor.
*
Expand All @@ -91,35 +84,10 @@ public function __construct($config)
$this->registerProviders();
$this->registerBase();
$this->initializeLogger();
$this->registerExceptionHandler();

Log::debug('Current configuration:', $config);
}

/**
* Set the exception handler.
*
* @param callable $callback
*
* @return $this
*/
public function setExceptionHandler(callable $callback)
{
$this->exceptionHandler = $callback;

return $this;
}

/**
* Return current exception handler.
*
* @return callable
*/
public function getExceptionHandler()
{
return $this->exceptionHandler;
}

/**
* Add a provider.
*
Expand Down Expand Up @@ -213,43 +181,6 @@ private function registerBase()
};
}

/**
* Register exception and error handler.
*/
private function registerExceptionHandler()
{
$logTemplate = '%s: %s in %s on line %s.';

$lastExceptionHandler = set_exception_handler(function ($e) use (&$lastExceptionHandler, $logTemplate) {
Log::error(sprintf($logTemplate, $e->getCode(), $e->getMessage(), $e->getFile(), $e->getLine()));

$this->exceptionHandler && call_user_func_array($this->exceptionHandler, [$e]);

if (is_callable($lastExceptionHandler)) {
return call_user_func($lastExceptionHandler, $e);
}
});

$errorHandler = function ($severity, $message, $file, $line) use ($logTemplate) {
Log::error(sprintf($logTemplate, $severity, $message, $file, $line));

if (error_reporting() & $severity) {
throw new ErrorException($message, 0, $severity, $file, $line);
}
};

set_error_handler($errorHandler);

register_shutdown_function(function () use ($errorHandler) {
$lastError = error_get_last();

if ($lastError['type'] === E_ERROR) {
// fatal error
$errorHandler(E_ERROR, $lastError['message'], $lastError['file'], $lastError['line']);
}
});
}

/**
* Initialize logger.
*/
Expand Down

0 comments on commit d5c98b8

Please sign in to comment.