00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 App::import('Controller', 'App');
00028
00029
00030
00031
00032
00033
00034
00035
00036 class CakeErrorController extends AppController {
00037 var $name = 'CakeError';
00038
00039
00040
00041
00042
00043 var $uses = array();
00044
00045
00046
00047
00048
00049
00050 function __construct() {
00051 parent::__construct();
00052 $this->_set(Router::getPaths());
00053 $this->params = Router::getParams();
00054 $this->constructClasses();
00055 $this->Component->initialize($this);
00056 $this->_set(array('cacheAction' => false, 'viewPath' => 'errors'));
00057 }
00058 }
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 class ErrorHandler extends Object {
00070
00071
00072
00073
00074
00075
00076 var $controller = null;
00077
00078
00079
00080
00081
00082
00083 function __construct($method, $messages) {
00084 App::import('Core', 'Sanitize');
00085 static $__previousError = null;
00086
00087 if ($__previousError != array($method, $messages)) {
00088 $__previousError = array($method, $messages);
00089 $this->controller =& new CakeErrorController();
00090 } else {
00091 $this->controller =& new Controller();
00092 $this->controller->viewPath = 'errors';
00093 }
00094
00095 $options = array('escape' => false);
00096 $messages = Sanitize::clean($messages, $options);
00097
00098 if (!isset($messages[0])) {
00099 $messages = array($messages);
00100 }
00101
00102 if (method_exists($this->controller, 'apperror')) {
00103 return $this->controller->appError($method, $messages);
00104 }
00105
00106 if (!in_array(strtolower($method), array_map('strtolower', get_class_methods($this)))) {
00107 $method = 'error';
00108 }
00109
00110 if ($method !== 'error') {
00111 if (Configure::read() == 0) {
00112 $method = 'error404';
00113 if (isset($code) && $code == 500) {
00114 $method = 'error500';
00115 }
00116 }
00117 }
00118 $this->dispatchMethod($method, $messages);
00119 $this->_stop();
00120 }
00121
00122
00123
00124
00125
00126
00127 function error($params) {
00128 extract($params, EXTR_OVERWRITE);
00129 $this->controller->set(array(
00130 'code' => $code,
00131 'name' => $name,
00132 'message' => $message,
00133 'title' => $code . ' ' . $name
00134 ));
00135 $this->_outputMessage('error404');
00136 }
00137
00138
00139
00140
00141
00142
00143 function error404($params) {
00144 extract($params, EXTR_OVERWRITE);
00145
00146 if (!isset($url)) {
00147 $url = $this->controller->here;
00148 }
00149 $url = Router::normalize($url);
00150 header("HTTP/1.0 404 Not Found");
00151 $this->controller->set(array(
00152 'code' => '404',
00153 'name' => __('Not Found', true),
00154 'message' => h($url),
00155 'base' => $this->controller->base
00156 ));
00157 $this->_outputMessage('error404');
00158 }
00159
00160
00161
00162
00163
00164
00165 function missingController($params) {
00166 extract($params, EXTR_OVERWRITE);
00167
00168 $controllerName = str_replace('Controller', '', $className);
00169 $this->controller->set(array(
00170 'controller' => $className,
00171 'controllerName' => $controllerName,
00172 'title' => __('Missing Controller', true)
00173 ));
00174 $this->_outputMessage('missingController');
00175 }
00176
00177
00178
00179
00180
00181
00182 function missingAction($params) {
00183 extract($params, EXTR_OVERWRITE);
00184
00185 $controllerName = str_replace('Controller', '', $className);
00186 $this->controller->set(array(
00187 'controller' => $className,
00188 'controllerName' => $controllerName,
00189 'action' => $action,
00190 'title' => __('Missing Method in Controller', true)
00191 ));
00192 $this->_outputMessage('missingAction');
00193 }
00194
00195
00196
00197
00198
00199
00200 function privateAction($params) {
00201 extract($params, EXTR_OVERWRITE);
00202
00203 $this->controller->set(array(
00204 'controller' => $className,
00205 'action' => $action,
00206 'title' => __('Trying to access private method in class', true)
00207 ));
00208 $this->_outputMessage('privateAction');
00209 }
00210
00211
00212
00213
00214
00215
00216 function missingTable($params) {
00217 extract($params, EXTR_OVERWRITE);
00218
00219 $this->controller->set(array(
00220 'model' => $className,
00221 'table' => $table,
00222 'title' => __('Missing Database Table', true)
00223 ));
00224 $this->_outputMessage('missingTable');
00225 }
00226
00227
00228
00229
00230
00231
00232 function missingDatabase($params = array()) {
00233 $this->controller->set(array(
00234 'title' => __('Scaffold Missing Database Connection', true)
00235 ));
00236 $this->_outputMessage('missingScaffolddb');
00237 }
00238
00239
00240
00241
00242
00243
00244 function missingView($params) {
00245 extract($params, EXTR_OVERWRITE);
00246
00247 $this->controller->set(array(
00248 'controller' => $className,
00249 'action' => $action,
00250 'file' => $file,
00251 'title' => __('Missing View', true)
00252 ));
00253 $this->_outputMessage('missingView');
00254 }
00255
00256
00257
00258
00259
00260
00261 function missingLayout($params) {
00262 extract($params, EXTR_OVERWRITE);
00263
00264 $this->controller->layout = 'default';
00265 $this->controller->set(array(
00266 'file' => $file,
00267 'title' => __('Missing Layout', true)
00268 ));
00269 $this->_outputMessage('missingLayout');
00270 }
00271
00272
00273
00274
00275
00276
00277 function missingConnection($params) {
00278 extract($params, EXTR_OVERWRITE);
00279
00280 $this->controller->set(array(
00281 'model' => $className,
00282 'title' => __('Missing Database Connection', true)
00283 ));
00284 $this->_outputMessage('missingConnection');
00285 }
00286
00287
00288
00289
00290
00291
00292 function missingHelperFile($params) {
00293 extract($params, EXTR_OVERWRITE);
00294
00295 $this->controller->set(array(
00296 'helperClass' => Inflector::camelize($helper) . "Helper",
00297 'file' => $file,
00298 'title' => __('Missing Helper File', true)
00299 ));
00300 $this->_outputMessage('missingHelperFile');
00301 }
00302
00303
00304
00305
00306
00307
00308 function missingHelperClass($params) {
00309 extract($params, EXTR_OVERWRITE);
00310
00311 $this->controller->set(array(
00312 'helperClass' => Inflector::camelize($helper) . "Helper",
00313 'file' => $file,
00314 'title' => __('Missing Helper Class', true)
00315 ));
00316 $this->_outputMessage('missingHelperClass');
00317 }
00318
00319
00320
00321
00322
00323
00324 function missingComponentFile($params) {
00325 extract($params, EXTR_OVERWRITE);
00326
00327 $this->controller->set(array(
00328 'controller' => $className,
00329 'component' => $component,
00330 'file' => $file,
00331 'title' => __('Missing Component File', true)
00332 ));
00333 $this->_outputMessage('missingComponentFile');
00334 }
00335
00336
00337
00338
00339
00340
00341 function missingComponentClass($params) {
00342 extract($params, EXTR_OVERWRITE);
00343
00344 $this->controller->set(array(
00345 'controller' => $className,
00346 'component' => $component,
00347 'file' => $file,
00348 'title' => __('Missing Component Class', true)
00349 ));
00350 $this->_outputMessage('missingComponentClass');
00351 }
00352
00353
00354
00355
00356
00357
00358 function missingModel($params) {
00359 extract($params, EXTR_OVERWRITE);
00360
00361 $this->controller->set(array(
00362 'model' => $className,
00363 'title' => __('Missing Model', true)
00364 ));
00365 $this->_outputMessage('missingModel');
00366 }
00367
00368
00369
00370
00371
00372 function _outputMessage($template) {
00373 $this->controller->render($template);
00374 $this->controller->afterFilter();
00375 echo $this->controller->output;
00376 }
00377 }
00378 ?>