Commit 842caa3a by Alexander Makarov

Yii-style for PHP fatal and parse errors

parent ab42ab2d
...@@ -126,6 +126,7 @@ class Application extends Module ...@@ -126,6 +126,7 @@ class Application extends Module
*/ */
public function init() public function init()
{ {
ob_start();
$this->preloadComponents(); $this->preloadComponents();
} }
...@@ -138,10 +139,27 @@ class Application extends Module ...@@ -138,10 +139,27 @@ class Application extends Module
*/ */
public function end($status = 0, $exit = true) public function end($status = 0, $exit = true)
{ {
$lastError = error_get_last();
if(isset($lastError['type']) && in_array($lastError['type'], array(E_ERROR, E_PARSE))) {
ob_end_clean();
$exception = new \ErrorException($lastError['message'], 0, $lastError['type'], $lastError['file'], $lastError['line']);
$this->logException($exception);
if (($handler = $this->getErrorHandler()) !== null) {
$handler->handle($exception);
} else {
$this->renderException($exception);
}
die(1);
}
if (!$this->_ended) { if (!$this->_ended) {
$this->_ended = true; $this->_ended = true;
$this->afterRequest(); $this->afterRequest();
} }
ob_end_flush();
if ($exit) { if ($exit) {
exit($status); exit($status);
} }
...@@ -155,6 +173,7 @@ class Application extends Module ...@@ -155,6 +173,7 @@ class Application extends Module
public function run() public function run()
{ {
$this->beforeRequest(); $this->beforeRequest();
register_shutdown_function(array($this,'end'),0,false);
$status = $this->processRequest(); $status = $this->processRequest();
$this->afterRequest(); $this->afterRequest();
return $status; return $status;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment