2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/* SVN FILE: $Id$ */
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2008-08-22 01:52:37 +00:00
|
|
|
* Error handler
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2008-08-22 01:52:37 +00:00
|
|
|
* Provides Error Capturing for Framework errors.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
|
|
|
|
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
|
|
|
* @filesource
|
2008-10-30 17:30:26 +00:00
|
|
|
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
|
|
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs
|
|
|
|
* @since CakePHP(tm) v 0.10.5.1732
|
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2008-06-11 15:46:31 +00:00
|
|
|
App::import('Controller', 'App');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-11 16:01:11 +00:00
|
|
|
/**
|
2008-08-22 01:52:37 +00:00
|
|
|
* Error Handling Controller
|
2008-06-11 16:01:11 +00:00
|
|
|
*
|
2008-08-22 01:52:37 +00:00
|
|
|
* Controller used by ErrorHandler to render error views.
|
2008-06-11 16:01:11 +00:00
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs
|
2008-06-11 16:01:11 +00:00
|
|
|
*/
|
2008-06-11 15:46:31 +00:00
|
|
|
class CakeErrorController extends AppController {
|
|
|
|
var $name = 'CakeError';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-08-22 01:52:37 +00:00
|
|
|
/**
|
|
|
|
* Uses Property
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2008-06-11 15:46:31 +00:00
|
|
|
var $uses = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-08-22 01:52:37 +00:00
|
|
|
/**
|
|
|
|
* __construct
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-06-11 15:46:31 +00:00
|
|
|
function __construct() {
|
|
|
|
parent::__construct();
|
|
|
|
$this->_set(Router::getPaths());
|
|
|
|
$this->params = Router::getParams();
|
|
|
|
$this->constructClasses();
|
2008-06-12 18:36:08 +00:00
|
|
|
$this->Component->initialize($this);
|
2008-06-11 15:46:31 +00:00
|
|
|
$this->_set(array('cacheAction' => false, 'viewPath' => 'errors'));
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2008-11-08 02:54:07 +00:00
|
|
|
* Error Handler.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2008-08-22 01:52:37 +00:00
|
|
|
* Captures and handles all cakeError() calls.
|
|
|
|
* Displays helpful framework errors when debug > 1.
|
|
|
|
* When debug < 1 cakeError() will render 404 or 500 errors.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class ErrorHandler extends Object {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Controller instance.
|
|
|
|
*
|
2009-03-19 21:10:13 +00:00
|
|
|
* @var Controller
|
2008-05-30 11:40:08 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
var $controller = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Class constructor.
|
|
|
|
*
|
|
|
|
* @param string $method Method producing the error
|
|
|
|
* @param array $messages Error messages
|
|
|
|
*/
|
|
|
|
function __construct($method, $messages) {
|
|
|
|
App::import('Core', 'Sanitize');
|
2008-08-22 01:52:37 +00:00
|
|
|
static $__previousError = null;
|
2008-11-08 02:54:07 +00:00
|
|
|
|
2008-08-22 01:52:37 +00:00
|
|
|
if ($__previousError != array($method, $messages)) {
|
|
|
|
$__previousError = array($method, $messages);
|
|
|
|
$this->controller =& new CakeErrorController();
|
|
|
|
} else {
|
|
|
|
$this->controller =& new Controller();
|
|
|
|
$this->controller->viewPath = 'errors';
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-07-22 23:33:01 +00:00
|
|
|
$options = array('escape' => false);
|
|
|
|
$messages = Sanitize::clean($messages, $options);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
if (!isset($messages[0])) {
|
|
|
|
$messages = array($messages);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (method_exists($this->controller, 'apperror')) {
|
|
|
|
return $this->controller->appError($method, $messages);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!in_array(strtolower($method), array_map('strtolower', get_class_methods($this)))) {
|
|
|
|
$method = 'error';
|
|
|
|
}
|
|
|
|
|
2008-06-21 15:35:17 +00:00
|
|
|
if ($method !== 'error') {
|
2008-10-23 00:10:44 +00:00
|
|
|
if (Configure::read() == 0) {
|
2008-06-21 15:35:17 +00:00
|
|
|
$method = 'error404';
|
2008-10-23 00:10:44 +00:00
|
|
|
if (isset($code) && $code == 500) {
|
2008-06-21 15:35:17 +00:00
|
|
|
$method = 'error500';
|
|
|
|
}
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2008-06-21 15:35:17 +00:00
|
|
|
$this->dispatchMethod($method, $messages);
|
|
|
|
$this->_stop();
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Displays an error page (e.g. 404 Not found).
|
|
|
|
*
|
|
|
|
* @param array $params Parameters for controller
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function error($params) {
|
|
|
|
extract($params, EXTR_OVERWRITE);
|
|
|
|
$this->controller->set(array(
|
|
|
|
'code' => $code,
|
|
|
|
'name' => $name,
|
|
|
|
'message' => $message,
|
|
|
|
'title' => $code . ' ' . $name
|
|
|
|
));
|
2008-11-11 00:14:38 +00:00
|
|
|
$this->_outputMessage('error404');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Convenience method to display a 404 page.
|
|
|
|
*
|
|
|
|
* @param array $params Parameters for controller
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function error404($params) {
|
|
|
|
extract($params, EXTR_OVERWRITE);
|
|
|
|
|
|
|
|
if (!isset($url)) {
|
|
|
|
$url = $this->controller->here;
|
|
|
|
}
|
|
|
|
$url = Router::normalize($url);
|
|
|
|
header("HTTP/1.0 404 Not Found");
|
|
|
|
$this->controller->set(array(
|
|
|
|
'code' => '404',
|
|
|
|
'name' => __('Not Found', true),
|
2009-02-13 14:56:00 +00:00
|
|
|
'message' => h($url),
|
2008-05-30 11:40:08 +00:00
|
|
|
'base' => $this->controller->base
|
|
|
|
));
|
2008-11-11 00:14:38 +00:00
|
|
|
$this->_outputMessage('error404');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Renders the Missing Controller web page.
|
|
|
|
*
|
|
|
|
* @param array $params Parameters for controller
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function missingController($params) {
|
|
|
|
extract($params, EXTR_OVERWRITE);
|
|
|
|
|
|
|
|
$controllerName = str_replace('Controller', '', $className);
|
2008-06-30 01:09:13 +00:00
|
|
|
$this->controller->set(array(
|
|
|
|
'controller' => $className,
|
|
|
|
'controllerName' => $controllerName,
|
|
|
|
'title' => __('Missing Controller', true)
|
|
|
|
));
|
2008-11-11 00:14:38 +00:00
|
|
|
$this->_outputMessage('missingController');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Renders the Missing Action web page.
|
|
|
|
*
|
|
|
|
* @param array $params Parameters for controller
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function missingAction($params) {
|
|
|
|
extract($params, EXTR_OVERWRITE);
|
|
|
|
|
|
|
|
$controllerName = str_replace('Controller', '', $className);
|
2008-06-30 01:09:13 +00:00
|
|
|
$this->controller->set(array(
|
|
|
|
'controller' => $className,
|
|
|
|
'controllerName' => $controllerName,
|
|
|
|
'action' => $action,
|
|
|
|
'title' => __('Missing Method in Controller', true)
|
|
|
|
));
|
2008-11-11 00:14:38 +00:00
|
|
|
$this->_outputMessage('missingAction');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Renders the Private Action web page.
|
|
|
|
*
|
|
|
|
* @param array $params Parameters for controller
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function privateAction($params) {
|
|
|
|
extract($params, EXTR_OVERWRITE);
|
|
|
|
|
2008-06-30 01:09:13 +00:00
|
|
|
$this->controller->set(array(
|
|
|
|
'controller' => $className,
|
|
|
|
'action' => $action,
|
|
|
|
'title' => __('Trying to access private method in class', true)
|
|
|
|
));
|
2008-11-11 00:14:38 +00:00
|
|
|
$this->_outputMessage('privateAction');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Renders the Missing Table web page.
|
|
|
|
*
|
|
|
|
* @param array $params Parameters for controller
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function missingTable($params) {
|
|
|
|
extract($params, EXTR_OVERWRITE);
|
|
|
|
|
2008-06-30 01:09:13 +00:00
|
|
|
$this->controller->set(array(
|
|
|
|
'model' => $className,
|
|
|
|
'table' => $table,
|
|
|
|
'title' => __('Missing Database Table', true)
|
|
|
|
));
|
2008-11-11 00:14:38 +00:00
|
|
|
$this->_outputMessage('missingTable');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Renders the Missing Database web page.
|
|
|
|
*
|
|
|
|
* @param array $params Parameters for controller
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function missingDatabase($params = array()) {
|
2008-06-30 01:09:13 +00:00
|
|
|
$this->controller->set(array(
|
|
|
|
'title' => __('Scaffold Missing Database Connection', true)
|
|
|
|
));
|
2008-11-11 00:14:38 +00:00
|
|
|
$this->_outputMessage('missingScaffolddb');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Renders the Missing View web page.
|
|
|
|
*
|
|
|
|
* @param array $params Parameters for controller
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function missingView($params) {
|
|
|
|
extract($params, EXTR_OVERWRITE);
|
|
|
|
|
2008-06-30 01:09:13 +00:00
|
|
|
$this->controller->set(array(
|
|
|
|
'controller' => $className,
|
|
|
|
'action' => $action,
|
|
|
|
'file' => $file,
|
|
|
|
'title' => __('Missing View', true)
|
|
|
|
));
|
2008-11-11 00:14:38 +00:00
|
|
|
$this->_outputMessage('missingView');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Renders the Missing Layout web page.
|
|
|
|
*
|
|
|
|
* @param array $params Parameters for controller
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function missingLayout($params) {
|
|
|
|
extract($params, EXTR_OVERWRITE);
|
|
|
|
|
|
|
|
$this->controller->layout = 'default';
|
2008-06-30 01:09:13 +00:00
|
|
|
$this->controller->set(array(
|
|
|
|
'file' => $file,
|
|
|
|
'title' => __('Missing Layout', true)
|
|
|
|
));
|
2008-11-11 00:14:38 +00:00
|
|
|
$this->_outputMessage('missingLayout');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Renders the Database Connection web page.
|
|
|
|
*
|
|
|
|
* @param array $params Parameters for controller
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function missingConnection($params) {
|
|
|
|
extract($params, EXTR_OVERWRITE);
|
|
|
|
|
2008-06-30 01:09:13 +00:00
|
|
|
$this->controller->set(array(
|
|
|
|
'model' => $className,
|
|
|
|
'title' => __('Missing Database Connection', true)
|
|
|
|
));
|
2008-11-11 00:14:38 +00:00
|
|
|
$this->_outputMessage('missingConnection');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Renders the Missing Helper file web page.
|
|
|
|
*
|
|
|
|
* @param array $params Parameters for controller
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function missingHelperFile($params) {
|
|
|
|
extract($params, EXTR_OVERWRITE);
|
2008-07-05 12:37:18 +00:00
|
|
|
|
2008-06-30 01:09:13 +00:00
|
|
|
$this->controller->set(array(
|
|
|
|
'helperClass' => Inflector::camelize($helper) . "Helper",
|
|
|
|
'file' => $file,
|
|
|
|
'title' => __('Missing Helper File', true)
|
|
|
|
));
|
2008-11-11 00:14:38 +00:00
|
|
|
$this->_outputMessage('missingHelperFile');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Renders the Missing Helper class web page.
|
|
|
|
*
|
|
|
|
* @param array $params Parameters for controller
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function missingHelperClass($params) {
|
|
|
|
extract($params, EXTR_OVERWRITE);
|
2008-07-05 12:37:18 +00:00
|
|
|
|
2008-06-30 01:09:13 +00:00
|
|
|
$this->controller->set(array(
|
|
|
|
'helperClass' => Inflector::camelize($helper) . "Helper",
|
|
|
|
'file' => $file,
|
|
|
|
'title' => __('Missing Helper Class', true)
|
|
|
|
));
|
2008-11-11 00:14:38 +00:00
|
|
|
$this->_outputMessage('missingHelperClass');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Renders the Missing Component file web page.
|
|
|
|
*
|
|
|
|
* @param array $params Parameters for controller
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function missingComponentFile($params) {
|
|
|
|
extract($params, EXTR_OVERWRITE);
|
|
|
|
|
2008-06-30 01:09:13 +00:00
|
|
|
$this->controller->set(array(
|
|
|
|
'controller' => $className,
|
|
|
|
'component' => $component,
|
|
|
|
'file' => $file,
|
|
|
|
'title' => __('Missing Component File', true)
|
|
|
|
));
|
2008-11-11 00:14:38 +00:00
|
|
|
$this->_outputMessage('missingComponentFile');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Renders the Missing Component class web page.
|
|
|
|
*
|
|
|
|
* @param array $params Parameters for controller
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function missingComponentClass($params) {
|
|
|
|
extract($params, EXTR_OVERWRITE);
|
|
|
|
|
2008-06-30 01:09:13 +00:00
|
|
|
$this->controller->set(array(
|
|
|
|
'controller' => $className,
|
|
|
|
'component' => $component,
|
|
|
|
'file' => $file,
|
|
|
|
'title' => __('Missing Component Class', true)
|
|
|
|
));
|
2008-11-11 00:14:38 +00:00
|
|
|
$this->_outputMessage('missingComponentClass');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Renders the Missing Model class web page.
|
|
|
|
*
|
|
|
|
* @param unknown_type $params Parameters for controller
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function missingModel($params) {
|
|
|
|
extract($params, EXTR_OVERWRITE);
|
|
|
|
|
2008-06-30 01:09:13 +00:00
|
|
|
$this->controller->set(array(
|
|
|
|
'model' => $className,
|
|
|
|
'title' => __('Missing Model', true)
|
|
|
|
));
|
2008-11-11 00:14:38 +00:00
|
|
|
$this->_outputMessage('missingModel');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Output message
|
|
|
|
*
|
2008-11-11 00:14:38 +00:00
|
|
|
* @access protected
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2008-11-11 00:14:38 +00:00
|
|
|
function _outputMessage($template) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->controller->render($template);
|
|
|
|
$this->controller->afterFilter();
|
2008-06-11 08:54:27 +00:00
|
|
|
echo $this->controller->output;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|