error.php

Go to the documentation of this file.
00001 <?php
00002 /* SVN FILE: $Id: error.php 8114 2009-03-17 21:10:28Z renan.saddam $ */
00003 /**
00004  * Error handler
00005  *
00006  * Provides Error Capturing for Framework errors.
00007  *
00008  * PHP versions 4 and 5
00009  *
00010  * CakePHP(tm) :  Rapid Development Framework (http://www.cakephp.org)
00011  * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
00012  *
00013  * Licensed under The MIT License
00014  * Redistributions of files must retain the above copyright notice.
00015  *
00016  * @filesource
00017  * @copyright     Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
00018  * @link          http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
00019  * @package       cake
00020  * @subpackage    cake.cake.libs
00021  * @since         CakePHP(tm) v 0.10.5.1732
00022  * @version       $Revision: 8114 $
00023  * @modifiedby    $LastChangedBy: renan.saddam $
00024  * @lastmodified  $Date: 2009-03-17 17:10:28 -0400 (Tue, 17 Mar 2009) $
00025  * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
00026  */
00027 App::import('Controller', 'App');
00028 /**
00029  * Error Handling Controller
00030  *
00031  * Controller used by ErrorHandler to render error views.
00032  *
00033  * @package       cake
00034  * @subpackage    cake.cake.libs
00035  */
00036 class CakeErrorController extends AppController {
00037     var $name = 'CakeError';
00038 /**
00039  * Uses Property
00040  *
00041  * @var array
00042  */
00043     var $uses = array();
00044 /**
00045  * __construct
00046  *
00047  * @access public
00048  * @return void
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  * Error Handler.
00061  *
00062  * Captures and handles all cakeError() calls.
00063  * Displays helpful framework errors when debug > 1.
00064  * When debug < 1 cakeError() will render 404 or 500 errors.
00065  *
00066  * @package       cake
00067  * @subpackage    cake.cake.libs
00068  */
00069 class ErrorHandler extends Object {
00070 /**
00071  * Controller instance.
00072  *
00073  * @var Controller
00074  * @access public
00075  */
00076     var $controller = null;
00077 /**
00078  * Class constructor.
00079  *
00080  * @param string $method Method producing the error
00081  * @param array $messages Error messages
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  * Displays an error page (e.g. 404 Not found).
00123  *
00124  * @param array $params Parameters for controller
00125  * @access public
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  * Convenience method to display a 404 page.
00139  *
00140  * @param array $params Parameters for controller
00141  * @access public
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  * Renders the Missing Controller web page.
00161  *
00162  * @param array $params Parameters for controller
00163  * @access public
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  * Renders the Missing Action web page.
00178  *
00179  * @param array $params Parameters for controller
00180  * @access public
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  * Renders the Private Action web page.
00196  *
00197  * @param array $params Parameters for controller
00198  * @access public
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  * Renders the Missing Table web page.
00212  *
00213  * @param array $params Parameters for controller
00214  * @access public
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  * Renders the Missing Database web page.
00228  *
00229  * @param array $params Parameters for controller
00230  * @access public
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  * Renders the Missing View web page.
00240  *
00241  * @param array $params Parameters for controller
00242  * @access public
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  * Renders the Missing Layout web page.
00257  *
00258  * @param array $params Parameters for controller
00259  * @access public
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  * Renders the Database Connection web page.
00273  *
00274  * @param array $params Parameters for controller
00275  * @access public
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  * Renders the Missing Helper file web page.
00288  *
00289  * @param array $params Parameters for controller
00290  * @access public
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  * Renders the Missing Helper class web page.
00304  *
00305  * @param array $params Parameters for controller
00306  * @access public
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  * Renders the Missing Component file web page.
00320  *
00321  * @param array $params Parameters for controller
00322  * @access public
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  * Renders the Missing Component class web page.
00337  *
00338  * @param array $params Parameters for controller
00339  * @access public
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  * Renders the Missing Model class web page.
00354  *
00355  * @param unknown_type $params Parameters for controller
00356  * @access public
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  * Output message
00369  *
00370  * @access protected
00371  */
00372     function _outputMessage($template) {
00373         $this->controller->render($template);
00374         $this->controller->afterFilter();
00375         echo $this->controller->output;
00376     }
00377 }
00378 ?>

Generated on Sun Nov 22 00:30:51 2009 for CakePHP 1.2.x.x (v1.2.4.8284) by doxygen 1.4.7