[ Index ] |
|
Code source de CakePHP 1.1.13.4450 |
1 <?php 2 /* SVN FILE: $Id: error.php 4409 2007-02-02 13:20:59Z phpnut $ */ 3 /** 4 * Short description for file. 5 * 6 * Long description for file 7 * 8 * PHP versions 4 and 5 9 * 10 * CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/> 11 * Copyright 2005-2007, Cake Software Foundation, Inc. 12 * 1785 E. Sahara Avenue, Suite 490-204 13 * Las Vegas, Nevada 89104 14 * 15 * Licensed under The MIT License 16 * Redistributions of files must retain the above copyright notice. 17 * 18 * @filesource 19 * @copyright Copyright 2005-2007, Cake Software Foundation, Inc. 20 * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project 21 * @package cake 22 * @subpackage cake.cake.libs 23 * @since CakePHP(tm) v 0.10.5.1732 24 * @version $Revision: 4409 $ 25 * @modifiedby $LastChangedBy: phpnut $ 26 * @lastmodified $Date: 2007-02-02 07:20:59 -0600 (Fri, 02 Feb 2007) $ 27 * @license http://www.opensource.org/licenses/mit-license.php The MIT License 28 */ 29 uses('sanitize'); 30 /** 31 * Short description for file. 32 * 33 * Long description for file 34 * 35 * @package cake 36 * @subpackage cake.cake.libs 37 */ 38 class ErrorHandler extends Object { 39 var $controller = null; 40 41 /** 42 * Class constructor. 43 * 44 * @param string $method 45 * @param array $messages 46 * @return unknown 47 */ 48 function __construct($method, $messages) { 49 parent::__construct(); 50 static $__previousError = null; 51 $allow = array('.', '/', '_', ' ', '-', '~'); 52 if(substr(PHP_OS,0,3) == "WIN") { 53 $allow = array_merge($allow, array('\\', ':') ); 54 } 55 $clean = new Sanitize(); 56 $messages = $clean->paranoid($messages, $allow); 57 if(!class_exists('Dispatcher')){ 58 require CAKE . 'dispatcher.php'; 59 } 60 $this->__dispatch =& new Dispatcher(); 61 62 if ($__previousError != array($method, $messages)) { 63 $__previousError = array($method, $messages); 64 65 if (!class_exists('AppController')) { 66 loadController(null); 67 } 68 69 $this->controller =& new AppController(); 70 $this->controller->_initComponents(); 71 $this->controller->cacheAction = false; 72 $this->__dispatch->start($this->controller); 73 74 if (method_exists($this->controller, 'apperror')) { 75 return $this->controller->appError($method, $messages); 76 } 77 } else { 78 $this->controller =& new Controller(); 79 $this->controller->cacheAction = false; 80 } 81 if (Configure::read() > 0 || $method == 'error') { 82 call_user_func_array(array(&$this, $method), $messages); 83 } else { 84 call_user_func_array(array(&$this, 'error404'), $messages); 85 } 86 } 87 /** 88 * Displays an error page (e.g. 404 Not found). 89 * 90 * @param array $params 91 */ 92 function error($params) { 93 extract($params); 94 $this->controller->base = $base; 95 $this->controller->webroot = $this->_webroot(); 96 $this->controller->viewPath='errors'; 97 $this->controller->set(array('code' => $code, 98 'name' => $name, 99 'message' => $message, 100 'title' => $code . ' ' . $name)); 101 $this->controller->render('error404'); 102 exit(); 103 } 104 /** 105 * Convenience method to display a 404 page. 106 * 107 * @param array $params 108 */ 109 function error404($params) { 110 extract($params); 111 112 if (!isset($url)) { 113 $url = $action; 114 } 115 if (!isset($message)) { 116 $message = ''; 117 } 118 if (!isset($base)) { 119 $base = ''; 120 } 121 122 header("HTTP/1.0 404 Not Found"); 123 $this->error(array('code' => '404', 124 'name' => 'Not found', 125 'message' => sprintf("The requested address %s was not found on this server.", $url, $message), 126 'base' => $base)); 127 exit(); 128 } 129 /** 130 * Renders the Missing Controller web page. 131 * 132 * @param array $params 133 */ 134 function missingController($params) { 135 extract($params); 136 $this->controller->base = $base; 137 $this->controller->webroot = $webroot; 138 $this->controller->viewPath ='errors'; 139 $controllerName = str_replace('Controller', '', $className); 140 $this->controller->set(array('controller' => $className, 141 'controllerName' => $controllerName, 142 'title' => 'Missing Controller')); 143 $this->controller->render('missingController'); 144 exit(); 145 } 146 /** 147 * Renders the Missing Action web page. 148 * 149 * @param array $params 150 */ 151 function missingAction($params) { 152 extract($params); 153 $this->controller->base = $base; 154 $this->controller->webroot = $webroot; 155 $this->controller->viewPath = 'errors'; 156 $this->controller->set(array('controller' => $className, 157 'action' => $action, 158 'title' => 'Missing Method in Controller')); 159 $this->controller->render('missingAction'); 160 exit(); 161 } 162 /** 163 * Renders the Private Action web page. 164 * 165 * @param array $params 166 */ 167 function privateAction($params) { 168 extract($params); 169 $this->controller->base = $base; 170 $this->controller->webroot = $webroot; 171 $this->controller->viewPath = 'errors'; 172 $this->controller->set(array('controller' => $className, 173 'action' => $action, 174 'title' => 'Trying to access private method in class')); 175 $this->controller->render('privateAction'); 176 exit(); 177 } 178 /** 179 * Renders the Missing Table web page. 180 * 181 * @param array $params 182 */ 183 function missingTable($params) { 184 extract($params); 185 $this->controller->viewPath = 'errors'; 186 $this->controller->webroot = $this->_webroot(); 187 $this->controller->set(array('model' => $className, 188 'table' => $table, 189 'title' => 'Missing Database Table')); 190 $this->controller->render('missingTable'); 191 exit(); 192 } 193 /** 194 * Renders the Missing Database web page. 195 * 196 * @param array $params 197 */ 198 function missingDatabase($params = array()) { 199 extract($params); 200 $this->controller->viewPath = 'errors'; 201 $this->controller->webroot = $this->_webroot(); 202 $this->controller->set(array('title' => 'Scaffold Missing Database Connection')); 203 $this->controller->render('missingScaffolddb'); 204 exit(); 205 } 206 /** 207 * Renders the Missing View web page. 208 * 209 * @param array $params 210 */ 211 function missingView($params) { 212 extract($params); 213 $this->controller->base = $base; 214 $this->controller->viewPath = 'errors'; 215 $this->controller->webroot = $this->_webroot(); 216 $this->controller->set(array('controller' => $className, 217 'action' => $action, 218 'file' => $file, 219 'title' => 'Missing View')); 220 $this->controller->render('missingView'); 221 exit(); 222 } 223 /** 224 * Renders the Missing Layout web page. 225 * 226 * @param array $params 227 */ 228 function missingLayout($params) { 229 extract($params); 230 $this->controller->base = $base; 231 $this->controller->viewPath = 'errors'; 232 $this->controller->webroot = $this->_webroot(); 233 $this->controller->layout = 'default'; 234 $this->controller->set(array('file' => $file, 235 'title' => 'Missing Layout')); 236 $this->controller->render('missingLayout'); 237 exit(); 238 } 239 /** 240 * Renders the Database Connection web page. 241 * 242 * @param array $params 243 */ 244 function missingConnection($params) { 245 extract($params); 246 $this->controller->viewPath = 'errors'; 247 $this->controller->webroot = $this->_webroot(); 248 $this->controller->set(array('model' => $className, 249 'title' => 'Missing Database Connection')); 250 $this->controller->render('missingConnection'); 251 exit(); 252 } 253 /** 254 * Renders the Missing Helper file web page. 255 * 256 * @param array $params 257 */ 258 function missingHelperFile($params) { 259 extract($params); 260 $this->controller->base = $base; 261 $this->controller->viewPath = 'errors'; 262 $this->controller->webroot = $this->_webroot(); 263 $this->controller->set(array('helperClass' => Inflector::camelize($helper) . "Helper", 264 'file' => $file, 265 'title' => 'Missing Helper File')); 266 $this->controller->render('missingHelperFile'); 267 exit(); 268 } 269 /** 270 * Renders the Missing Helper class web page. 271 * 272 * @param array $params 273 */ 274 function missingHelperClass($params) { 275 extract($params); 276 $this->controller->base = $base; 277 $this->controller->viewPath = 'errors'; 278 $this->controller->webroot = $this->_webroot(); 279 $this->controller->set(array('helperClass' => Inflector::camelize($helper) . "Helper", 280 'file' => $file, 281 'title' => 'Missing Helper Class')); 282 $this->controller->render('missingHelperClass'); 283 exit(); 284 } 285 /** 286 * Renders the Missing Component file web page. 287 * 288 * @param array $params 289 */ 290 function missingComponentFile($params) { 291 extract($params); 292 $this->controller->base = $base; 293 $this->controller->viewPath = 'errors'; 294 $this->controller->webroot = $this->_webroot(); 295 $this->controller->set(array('controller' => $className, 296 'component' => $component, 297 'file' => $file, 298 'title' => 'Missing Component File')); 299 $this->controller->render('missingComponentFile'); 300 exit(); 301 } 302 /** 303 * Renders the Missing Component class web page. 304 * 305 * @param array $params 306 */ 307 function missingComponentClass($params) { 308 extract($params); 309 $this->controller->base = $base; 310 $this->controller->viewPath = 'errors'; 311 $this->controller->webroot = $this->_webroot(); 312 $this->controller->set(array('controller' => $className, 313 'component' => $component, 314 'file' => $file, 315 'title' => 'Missing Component Class')); 316 $this->controller->render('missingComponentClass'); 317 exit(); 318 } 319 /** 320 * Renders the Missing Model class web page. 321 * 322 * @param unknown_type $params 323 */ 324 function missingModel($params) { 325 extract($params); 326 $this->controller->base = $base; 327 $this->controller->viewPath = 'errors'; 328 $this->controller->webroot = $this->_webroot(); 329 $this->controller->set(array('model' => $className, 330 'title' => 'Missing Model')); 331 $this->controller->render('missingModel'); 332 exit(); 333 } 334 /** 335 * Path to the web root. 336 * 337 * @return string full web root path 338 */ 339 function _webroot() { 340 $this->__dispatch->baseUrl(); 341 return $this->__dispatch->webroot; 342 } 343 } 344 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 19:27:47 2007 | par Balluche grâce à PHPXref 0.7 |