2010-09-02 21:49:00 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* ErrorHandler for Console Shells
|
|
|
|
*
|
2010-10-03 16:38:58 +00:00
|
|
|
* PHP 5
|
2010-09-02 21:49:00 +00:00
|
|
|
*
|
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
|
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
|
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.console
|
2010-10-03 05:40:12 +00:00
|
|
|
* @since CakePHP(tm) v 2.0
|
2010-09-02 21:49:00 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
|
|
|
*/
|
2010-12-07 05:56:10 +00:00
|
|
|
App::uses('ErrorHandler', 'Error');
|
|
|
|
App::uses('ConsoleOutput', 'Console');
|
2010-09-02 21:49:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Error Handler for Cake console. Does simple printing of the
|
|
|
|
* exception that occurred and the stack trace of the error.
|
|
|
|
*
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.console
|
|
|
|
*/
|
|
|
|
class ConsoleErrorHandler extends ErrorHandler {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Standard error stream.
|
|
|
|
*
|
|
|
|
* @var filehandle
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-11-15 03:47:35 +00:00
|
|
|
public static $stderr;
|
2010-09-02 21:49:00 +00:00
|
|
|
|
|
|
|
/**
|
2010-11-15 03:47:35 +00:00
|
|
|
* Get the stderr object for the console error handling.
|
2010-09-02 21:49:00 +00:00
|
|
|
*
|
|
|
|
* @param Exception $error Exception to handle.
|
|
|
|
* @param array $messages Error messages
|
|
|
|
*/
|
2010-11-15 03:47:35 +00:00
|
|
|
public static function getStderr() {
|
|
|
|
if (empty(self::$stderr)) {
|
|
|
|
self::$stderr = new ConsoleOutput('php://stderr');
|
|
|
|
}
|
|
|
|
return self::$stderr;
|
2010-09-02 21:49:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a exception in the console environment.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-12-04 19:20:50 +00:00
|
|
|
public static function handleException(Exception $exception) {
|
2010-11-15 03:47:35 +00:00
|
|
|
$stderr = self::getStderr();
|
|
|
|
$stderr->write(sprintf(
|
|
|
|
__("<error>Error:</error> %s\n%s"),
|
|
|
|
$exception->getMessage(),
|
|
|
|
$exception->getTraceAsString()
|
|
|
|
));
|
2010-09-02 22:02:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-11-15 03:47:35 +00:00
|
|
|
* Handle errors in the console environment.
|
2010-09-02 22:02:58 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-11-15 03:47:35 +00:00
|
|
|
public static function handleError($code, $description, $file = null, $line = null, $context = null) {
|
2010-12-02 03:44:31 +00:00
|
|
|
if (error_reporting() === 0) {
|
|
|
|
return;
|
|
|
|
}
|
2010-11-15 03:47:35 +00:00
|
|
|
$stderr = self::getStderr();
|
|
|
|
list($name, $log) = self::_mapErrorCode($code);
|
2010-12-05 01:37:13 +00:00
|
|
|
$message = __('%s in [%s, line %s]', $description, $file, $line);
|
|
|
|
$stderr->write(__("<error>%s Error:</error> %s\n", $name, $message));
|
2010-11-26 04:16:27 +00:00
|
|
|
|
|
|
|
if (Configure::read('debug') == 0) {
|
|
|
|
App::import('Core', 'CakeLog');
|
|
|
|
CakeLog::write($log, $message);
|
|
|
|
}
|
2010-09-02 22:02:58 +00:00
|
|
|
}
|
2010-09-05 15:22:39 +00:00
|
|
|
|
2010-09-02 21:49:00 +00:00
|
|
|
/**
|
2010-11-15 03:47:35 +00:00
|
|
|
* undocumented function
|
2010-09-02 21:49:00 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-11-15 03:47:35 +00:00
|
|
|
public function render() {
|
2010-10-04 01:53:23 +00:00
|
|
|
$this->stderr->write(sprintf(
|
|
|
|
__("<error>Error:</error> %s\n%s"),
|
|
|
|
$this->error->getMessage(),
|
|
|
|
$this->error->getTraceAsString()
|
|
|
|
));
|
2010-09-02 21:49:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|