1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
|
<?php
/* SVN FILE: $Id: error.php 7118 2008-06-04 20:49:29Z gwoo $ */
/**
* ErrorHandler for Console Shells
*
* Long description for file
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
* Copyright 2005-2008, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc.
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake
* @subpackage cake.cake.console
* @since CakePHP(tm) v 1.2.0.5074
* @version $Revision: 7118 $
* @modifiedby $LastChangedBy: gwoo $
* @lastmodified $Date: 2008-06-04 13:49:29 -0700 (Wed, 04 Jun 2008) $
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Error Handler for Cake console.
*
* @package cake
* @subpackage cake.cake.console
*/
class ErrorHandler extends Object {
/**
* Standard output stream.
*
* @var filehandle
* @access public
*/
var $stdout;
/**
* Standard error stream.
*
* @var filehandle
* @access public
*/
var $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');
if (Configure::read() > 0 || $method == 'error') {
call_user_func_array(array(&$this, $method), $messages);
} else {
call_user_func_array(array(&$this, 'error404'), $messages);
}
}
/**
* Displays an error page (e.g. 404 Not found).
*
* @param array $params Parameters (code, name, and message)
* @access 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)
* @access 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.", true), $url, $message)));
$this->_stop();
}
/**
* Renders the Missing Controller web page.
*
* @param array $params Parameters (className)
* @access public
*/
function missingController($params) {
extract($params, EXTR_OVERWRITE);
$controllerName = str_replace('Controller', '', $className);
$this->stderr(sprintf(__("Missing Controller '%s'", true), $controllerName));
$this->_stop();
}
/**
* Renders the Missing Action web page.
*
* @param array $params Parameters (action, className)
* @access public
*/
function missingAction($params) {
extract($params, EXTR_OVERWRITE);
$this->stderr(sprintf(__("Missing Method '%s' in '%s'", true), $action, $className));
$this->_stop();
}
/**
* Renders the Private Action web page.
*
* @param array $params Parameters (action, className)
* @access public
*/
function privateAction($params) {
extract($params, EXTR_OVERWRITE);
$this->stderr(sprintf(__("Trying to access private method '%s' in '%s'", true), $action, $className));
$this->_stop();
}
/**
* Renders the Missing Table web page.
*
* @param array $params Parameters (table, className)
* @access public
*/
function missingTable($params) {
extract($params, EXTR_OVERWRITE);
$this->stderr(sprintf(__("Missing database table '%s' for model '%s'", true), $table, $className));
$this->_stop();
}
/**
* Renders the Missing Database web page.
*
* @param array $params Parameters
* @access public
*/
function missingDatabase($params = array()) {
extract($params, EXTR_OVERWRITE);
$this->stderr(__("Missing Database", true));
$this->_stop();
}
/**
* Renders the Missing View web page.
*
* @param array $params Parameters (file, action, className)
* @access public
*/
function missingView($params) {
extract($params, EXTR_OVERWRITE);
$this->stderr(sprintf(__("Missing View '%s' for '%s' in '%s'", true), $file, $action, $className));
$this->_stop();
}
/**
* Renders the Missing Layout web page.
*
* @param array $params Parameters (file)
* @access public
*/
function missingLayout($params) {
extract($params, EXTR_OVERWRITE);
$this->stderr(sprintf(__("Missing Layout '%s'", true), $file));
$this->_stop();
}
/**
* Renders the Database Connection web page.
*
* @param array $params Parameters
* @access public
*/
function missingConnection($params) {
extract($params, EXTR_OVERWRITE);
$this->stderr(__("Missing Database Connection. Try 'cake bake'", true));
$this->_stop();
}
/**
* Renders the Missing Helper file web page.
*
* @param array $params Parameters (file, helper)
* @access public
*/
function missingHelperFile($params) {
extract($params, EXTR_OVERWRITE);
$this->stderr(sprintf(__("Missing Helper file '%s' for '%s'", true), $file, Inflector::camelize($helper)));
$this->_stop();
}
/**
* Renders the Missing Helper class web page.
*
* @param array $params Parameters (file, helper)
* @access public
*/
function missingHelperClass($params) {
extract($params, EXTR_OVERWRITE);
$this->stderr(sprintf(__("Missing Helper class '%s' in '%s'", true), Inflector::camelize($helper), $file));
$this->_stop();
}
/**
* Renders the Missing Component file web page.
*
* @param array $params Parameters (file, component)
* @access public
*/
function missingComponentFile($params) {
extract($params, EXTR_OVERWRITE);
$this->stderr(sprintf(__("Missing Component file '%s' for '%s'", true), $file, Inflector::camelize($component)));
$this->_stop();
}
/**
* Renders the Missing Component class web page.
*
* @param array $params Parameters (file, component)
* @access public
*/
function missingComponentClass($params) {
extract($params, EXTR_OVERWRITE);
$this->stderr(sprintf(__("Missing Component class '%s' in '%s'", true), Inflector::camelize($component), $file));
$this->_stop();
}
/**
* Renders the Missing Model class web page.
*
* @param array $params Parameters (className)
* @access public
*/
function missingModel($params) {
extract($params, EXTR_OVERWRITE);
$this->stderr(sprintf(__("Missing model '%s'", true), $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.
* @access 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.
* @access public
*/
function stderr($string) {
fwrite($this->stderr, "Error: ". $string . "\n");
}
}
?>
|