mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Add support for custom console error handling
Both errors and exceptions can be configured for the console at the application layer now. Fixes #2696
This commit is contained in:
parent
69e63b11a4
commit
34e1afd8ef
1 changed files with 26 additions and 4 deletions
|
@ -134,10 +134,8 @@ class ShellDispatcher {
|
||||||
include_once CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'Console' . DS . 'Templates' . DS . 'skel' . DS . 'Config' . DS . 'core.php';
|
include_once CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'Console' . DS . 'Templates' . DS . 'skel' . DS . 'Config' . DS . 'core.php';
|
||||||
App::build();
|
App::build();
|
||||||
}
|
}
|
||||||
require_once CAKE . 'Console' . DS . 'ConsoleErrorHandler.php';
|
|
||||||
$ErrorHandler = new ConsoleErrorHandler();
|
$this->setErrorHandlers();
|
||||||
set_exception_handler(array($ErrorHandler, 'handleException'));
|
|
||||||
set_error_handler(array($ErrorHandler, 'handleError'), Configure::read('Error.level'));
|
|
||||||
|
|
||||||
if (!defined('FULL_BASE_URL')) {
|
if (!defined('FULL_BASE_URL')) {
|
||||||
define('FULL_BASE_URL', 'http://localhost');
|
define('FULL_BASE_URL', 'http://localhost');
|
||||||
|
@ -146,6 +144,30 @@ class ShellDispatcher {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the error/exception handlers for the console
|
||||||
|
* based on the `Error.consoleHandler`, and `Exception.consoleHandler` values
|
||||||
|
* if they are set. If they are not set, the default ConsoleErrorHandler will be
|
||||||
|
* used.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setErrorHandlers() {
|
||||||
|
App::uses('ConsoleErrorHandler', 'Console');
|
||||||
|
$error = Configure::read('Error');
|
||||||
|
$exception = Configure::read('Exception');
|
||||||
|
|
||||||
|
$errorHandler = new ConsoleErrorHandler();
|
||||||
|
if (empty($error['consoleHandler'])) {
|
||||||
|
$error['consoleHandler'] = array($errorHandler, 'handleError');
|
||||||
|
}
|
||||||
|
if (empty($exception['consoleHandler'])) {
|
||||||
|
$exception['consoleHandler'] = array($errorHandler, 'handleException');
|
||||||
|
}
|
||||||
|
set_exception_handler($exception['consoleHandler']);
|
||||||
|
set_error_handler($error['consoleHandler'], Configure::read('Error.level'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dispatches a CLI request
|
* Dispatches a CLI request
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue