mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Moving ErrorHandler to ConsoleErrorHandler so it doesn't have classname conflicts.
Making the console use a subclass of ErrorHandler.
This commit is contained in:
parent
034aaa7462
commit
60e44660c3
2 changed files with 99 additions and 249 deletions
99
cake/console/console_error_handler.php
Normal file
99
cake/console/console_error_handler.php
Normal file
|
@ -0,0 +1,99 @@
|
|||
<?php
|
||||
/**
|
||||
* ErrorHandler for Console Shells
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* 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
|
||||
* @since CakePHP(tm) v 1.2.0.5074
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
App::import('Core', 'ErrorHandler');
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public $stderr;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param Exception $error Exception to handle.
|
||||
* @param array $messages Error messages
|
||||
*/
|
||||
function __construct($error) {
|
||||
$this->stderr = fopen('php://stderr', 'w');
|
||||
parent::__construct($error);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a exception in the console environment.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function handleException($exception) {
|
||||
$error = new ConsoleErrorHandler($exception);
|
||||
$error->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Do nothing, no controllers are needed in the console.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _getController($exception) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite how _cakeError behaves for console. There is no reason
|
||||
* to prepare urls as they are not relevant for this.
|
||||
*
|
||||
* @param $error Exception Exception being handled.
|
||||
* @return void
|
||||
*/
|
||||
protected function _cakeError($error) {
|
||||
$this->_outputMessage('');
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the exception to STDERR.
|
||||
*
|
||||
* @param string $template The name of the template to render.
|
||||
* @return void
|
||||
*/
|
||||
public function _outputMessage($template) {
|
||||
$this->stderr($this->error->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs to the stderr filehandle.
|
||||
*
|
||||
* @param string $string Error text to output.
|
||||
*/
|
||||
public function stderr($string) {
|
||||
fwrite($this->stderr, "Error: ". $string . "\n");
|
||||
}
|
||||
}
|
|
@ -1,249 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* ErrorHandler for Console Shells
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* 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
|
||||
* @since CakePHP(tm) v 1.2.0.5074
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
App::import('Core', 'ErrorHandler');
|
||||
/**
|
||||
* Error Handler for Cake console.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console
|
||||
*/
|
||||
class ConsoleErrorHandler extends ErrorHandler {
|
||||
|
||||
/**
|
||||
* Standard output stream.
|
||||
*
|
||||
* @var filehandle
|
||||
* @access public
|
||||
*/
|
||||
public $stdout;
|
||||
|
||||
/**
|
||||
* Standard error stream.
|
||||
*
|
||||
* @var filehandle
|
||||
* @access public
|
||||
*/
|
||||
public $stderr;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param string $method Method dispatching an error
|
||||
* @param array $messages Error messages
|
||||
*/
|
||||
function __construct($method, $messages) {
|
||||
$this->stdout = fopen('php://stdout', 'w');
|
||||
$this->stderr = fopen('php://stderr', 'w');
|
||||
call_user_func_array(array(&$this, $method), $messages);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays an error page (e.g. 404 Not found).
|
||||
*
|
||||
* @param array $params Parameters (code, name, and message)
|
||||
*/
|
||||
public function error($params) {
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
$this->stderr($code . $name . $message."\n");
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to display a 404 page.
|
||||
*
|
||||
* @param array $params Parameters (url, message)
|
||||
*/
|
||||
public function error404($params) {
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
$this->error(array(
|
||||
'code' => '404',
|
||||
'name' => 'Not found',
|
||||
'message' => sprintf(__('The requested address %s was not found on this server.'), $url, $message)
|
||||
));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Missing Controller web page.
|
||||
*
|
||||
* @param array $params Parameters (className)
|
||||
*/
|
||||
public function missingController($params) {
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
$controllerName = str_replace('Controller', '', $className);
|
||||
$this->stderr(sprintf(__("Missing Controller '%s'"), $controllerName));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Missing Action web page.
|
||||
*
|
||||
* @param array $params Parameters (action, className)
|
||||
*/
|
||||
public function missingAction($params) {
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
$this->stderr(sprintf(__("Missing Method '%s' in '%s'"), $action, $className));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Private Action web page.
|
||||
*
|
||||
* @param array $params Parameters (action, className)
|
||||
*/
|
||||
public function privateAction($params) {
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
$this->stderr(sprintf(__("Trying to access private method '%s' in '%s'"), $action, $className));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Missing Table web page.
|
||||
*
|
||||
* @param array $params Parameters (table, className)
|
||||
*/
|
||||
public function missingTable($params) {
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
$this->stderr(sprintf(__("Missing database table '%s' for model '%s'"), $table, $className));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Missing Database web page.
|
||||
*
|
||||
* @param array $params Parameters
|
||||
*/
|
||||
public function missingDatabase($params = array()) {
|
||||
$this->stderr(__('Missing Database'));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Missing View web page.
|
||||
*
|
||||
* @param array $params Parameters (file, action, className)
|
||||
*/
|
||||
public function missingView($params) {
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
$this->stderr(sprintf(__("Missing View '%s' for '%s' in '%s'"), $file, $action, $className));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Missing Layout web page.
|
||||
*
|
||||
* @param array $params Parameters (file)
|
||||
*/
|
||||
public function missingLayout($params) {
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
$this->stderr(sprintf(__("Missing Layout '%s'"), $file));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Database Connection web page.
|
||||
*
|
||||
* @param array $params Parameters
|
||||
*/
|
||||
public function missingConnection($params) {
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
$this->stderr(__("Missing Database Connection. Try 'cake bake'"));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Missing Helper file web page.
|
||||
*
|
||||
* @param array $params Parameters (file, helper)
|
||||
*/
|
||||
public function missingHelperFile($params) {
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
$this->stderr(sprintf(__("Missing Helper file '%s' for '%s'"), $file, Inflector::camelize($helper)));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Missing Helper class web page.
|
||||
*
|
||||
* @param array $params Parameters (file, helper)
|
||||
*/
|
||||
public function missingHelperClass($params) {
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
$this->stderr(sprintf(__("Missing Helper class '%s' in '%s'"), Inflector::camelize($helper), $file));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Missing Component file web page.
|
||||
*
|
||||
* @param array $params Parameters (file, component)
|
||||
*/
|
||||
public function missingComponentFile($params) {
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
$this->stderr(sprintf(__("Missing Component file '%s' for '%s'"), $file, Inflector::camelize($component)));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Missing Component class web page.
|
||||
*
|
||||
* @param array $params Parameters (file, component)
|
||||
*/
|
||||
public function missingComponentClass($params) {
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
$this->stderr(sprintf(__("Missing Component class '%s' in '%s'"), Inflector::camelize($component), $file));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Missing Model class web page.
|
||||
*
|
||||
* @param array $params Parameters (className)
|
||||
*/
|
||||
public function missingModel($params) {
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
$this->stderr(sprintf(__("Missing model '%s'"), $className));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs to the stdout filehandle.
|
||||
*
|
||||
* @param string $string String to output.
|
||||
* @param boolean $newline If true, the outputs gets an added newline.
|
||||
*/
|
||||
public function stdout($string, $newline = true) {
|
||||
if ($newline) {
|
||||
fwrite($this->stdout, $string . "\n");
|
||||
} else {
|
||||
fwrite($this->stdout, $string);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs to the stderr filehandle.
|
||||
*
|
||||
* @param string $string Error text to output.
|
||||
*/
|
||||
public function stderr($string) {
|
||||
fwrite($this->stderr, "Error: ". $string . "\n");
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue