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