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