2006-01-12 02:10:47 +00:00
|
|
|
<?php
|
|
|
|
/* SVN FILE: $Id$ */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Short description for file.
|
|
|
|
*
|
|
|
|
* Long description for file
|
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
|
|
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
2006-01-20 07:46:14 +00:00
|
|
|
* Copyright (c) 2006, Cake Software Foundation, Inc.
|
2006-01-12 02:10:47 +00:00
|
|
|
* 1785 E. Sahara Avenue, Suite 490-204
|
|
|
|
* Las Vegas, Nevada 89104
|
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
|
|
|
* @filesource
|
2006-01-20 07:46:14 +00:00
|
|
|
* @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
2006-01-12 02:10:47 +00:00
|
|
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs
|
|
|
|
* @since CakePHP v 0.10.5.1732
|
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Short description for file.
|
|
|
|
*
|
|
|
|
* Long description for file
|
|
|
|
*
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs
|
|
|
|
* @since CakePHP v 0.10.5.1732
|
|
|
|
*/
|
|
|
|
class ErrorHandler extends Object
|
|
|
|
{
|
|
|
|
var $controller = null;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class constructor.
|
|
|
|
*/
|
|
|
|
function __construct($method, $messages)
|
|
|
|
{
|
2006-03-28 02:44:55 +00:00
|
|
|
parent::__construct();
|
|
|
|
static $__previousError = null;
|
|
|
|
|
|
|
|
if ($__previousError != array($method, $messages))
|
2006-02-01 13:26:23 +00:00
|
|
|
{
|
2006-03-28 02:44:55 +00:00
|
|
|
if(!class_exists('AppController'))
|
|
|
|
{
|
|
|
|
loadController(null);
|
|
|
|
}
|
|
|
|
$this->controller =& new AppController();
|
2006-02-01 13:26:23 +00:00
|
|
|
}
|
2006-03-28 02:44:55 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->controller =& new Controller();
|
|
|
|
}
|
|
|
|
$__previousError = array($method, $messages);
|
|
|
|
|
2006-02-01 13:26:23 +00:00
|
|
|
if(DEBUG > 0 || $method == 'error')
|
2006-01-12 02:10:47 +00:00
|
|
|
{
|
|
|
|
call_user_func_array(array(&$this, $method), $messages);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
call_user_func_array(array(&$this, 'error404'), $messages);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays an error page (e.g. 404 Not found).
|
|
|
|
*
|
|
|
|
* @param int $code Error code (e.g. 404)
|
|
|
|
* @param string $name Name of the error message (e.g. Not found)
|
|
|
|
* @param string $message
|
|
|
|
* @return unknown
|
|
|
|
*/
|
|
|
|
function error ($params)
|
|
|
|
{
|
|
|
|
extract($params);
|
2006-04-24 16:24:57 +00:00
|
|
|
$this->controller->base = $base;
|
2006-01-12 02:10:47 +00:00
|
|
|
$this->controller->webroot = $this->_webroot();
|
2006-04-11 15:46:29 +00:00
|
|
|
$this->controller->viewPath = 'errors';
|
2006-01-12 02:10:47 +00:00
|
|
|
$this->controller->set(array('code'=>$code,
|
|
|
|
'name'=>$name,
|
|
|
|
'message'=>$message,
|
|
|
|
'title' => $code.' '. $name));
|
2006-04-11 15:46:29 +00:00
|
|
|
$this->controller->render('error404');
|
2006-03-16 01:50:55 +00:00
|
|
|
exit();
|
2006-01-12 02:10:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience method to display a 404 page.
|
|
|
|
*
|
|
|
|
* @param string $url URL that spawned this message, to be included in the output.
|
|
|
|
* @param string $message Message text for the 404 page.
|
|
|
|
*/
|
|
|
|
function error404 ($params)
|
|
|
|
{
|
|
|
|
extract($params);
|
|
|
|
if(!isset($url))
|
|
|
|
{
|
|
|
|
$url = $action;
|
|
|
|
}
|
|
|
|
if(!isset($message))
|
|
|
|
{
|
|
|
|
$message = '';
|
|
|
|
}
|
2006-04-24 16:24:57 +00:00
|
|
|
if(!isset($base))
|
|
|
|
{
|
|
|
|
$base = '';
|
|
|
|
}
|
2006-03-26 09:59:40 +00:00
|
|
|
|
2006-01-12 02:10:47 +00:00
|
|
|
header("HTTP/1.0 404 Not Found");
|
2006-03-26 09:59:40 +00:00
|
|
|
$this->error(
|
|
|
|
array('code' => '404',
|
|
|
|
'name' => 'Not found',
|
2006-04-24 16:24:57 +00:00
|
|
|
'message' => sprintf(__("The requested address %s was not found on this server.", true), $url, $message),
|
|
|
|
'base' => $base
|
2006-03-26 09:59:40 +00:00
|
|
|
)
|
|
|
|
);
|
2006-03-16 01:50:55 +00:00
|
|
|
exit();
|
2006-01-12 02:10:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the Missing Controller web page.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function missingController($params)
|
|
|
|
{
|
|
|
|
extract($params);
|
2006-04-24 16:24:57 +00:00
|
|
|
$this->controller->base = $base;
|
2006-01-12 02:10:47 +00:00
|
|
|
$this->controller->webroot = $webroot;
|
2006-04-24 16:24:57 +00:00
|
|
|
$this->controller->viewPath = 'errors';
|
2006-01-12 02:10:47 +00:00
|
|
|
$this->controller->set(array('controller' => $className,
|
|
|
|
'title' => 'Missing Controller'));
|
2006-04-24 16:24:57 +00:00
|
|
|
$this->controller->render('missingController');
|
2006-03-16 01:50:55 +00:00
|
|
|
exit();
|
2006-01-12 02:10:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the Missing Action web page.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function missingAction($params)
|
|
|
|
{
|
|
|
|
extract($params);
|
2006-04-24 16:24:57 +00:00
|
|
|
$this->controller->base = $base;
|
2006-01-12 02:10:47 +00:00
|
|
|
$this->controller->webroot = $webroot;
|
2006-04-24 16:24:57 +00:00
|
|
|
$this->controller->viewPath = 'errors';
|
2006-01-12 02:10:47 +00:00
|
|
|
$this->controller->set(array('controller' => $className,
|
|
|
|
'action' => $action,
|
|
|
|
'title' => 'Missing Method in Controller'));
|
2006-04-24 16:24:57 +00:00
|
|
|
$this->controller->render('missingAction');
|
2006-03-16 01:50:55 +00:00
|
|
|
exit();
|
2006-01-12 02:10:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the Private Action web page.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function privateAction($params)
|
|
|
|
{
|
|
|
|
extract($params);
|
2006-04-24 16:24:57 +00:00
|
|
|
$this->controller->base = $base;
|
2006-01-12 02:10:47 +00:00
|
|
|
$this->controller->webroot = $webroot;
|
2006-04-24 16:24:57 +00:00
|
|
|
$this->controller->viewPath = 'errors';
|
2006-01-12 02:10:47 +00:00
|
|
|
$this->controller->set(array('controller' => $className,
|
|
|
|
'action' => $action,
|
|
|
|
'title' => 'Trying to access private method in class'));
|
2006-04-24 16:24:57 +00:00
|
|
|
$this->controller->render('privateAction');
|
2006-03-16 01:50:55 +00:00
|
|
|
exit();
|
2006-01-12 02:10:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the Missing Table web page.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function missingTable($params)
|
|
|
|
{
|
|
|
|
extract($params);
|
2006-04-24 16:24:57 +00:00
|
|
|
$this->controller->viewPath = 'errors';
|
2006-01-12 02:10:47 +00:00
|
|
|
$this->controller->webroot = $this->_webroot();
|
|
|
|
$this->controller->set(array('model' => $className,
|
|
|
|
'table' => $table,
|
|
|
|
'title' => 'Missing Database Table'));
|
2006-04-24 16:24:57 +00:00
|
|
|
$this->controller->render('missingTable');
|
2006-01-12 02:10:47 +00:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the Missing Database web page.
|
|
|
|
*
|
|
|
|
*/
|
2006-03-16 01:50:55 +00:00
|
|
|
function missingDatabase($params = array())
|
2006-01-12 02:10:47 +00:00
|
|
|
{
|
|
|
|
extract($params);
|
2006-04-24 16:24:57 +00:00
|
|
|
$this->controller->viewPath = 'errors';
|
2006-03-16 01:50:55 +00:00
|
|
|
$this->controller->webroot = $this->_webroot();
|
2006-01-12 02:10:47 +00:00
|
|
|
$this->controller->set(array('title' => 'Scaffold Missing Database Connection'));
|
2006-04-24 16:24:57 +00:00
|
|
|
$this->controller->render('missingScaffolddb');
|
2006-03-16 01:50:55 +00:00
|
|
|
exit();
|
2006-01-12 02:10:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the Missing View web page.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function missingView($params)
|
|
|
|
{
|
|
|
|
extract($params);
|
2006-04-24 16:24:57 +00:00
|
|
|
$this->controller->base = $base;
|
|
|
|
$this->controller->viewPath = 'errors';
|
2006-01-13 23:53:23 +00:00
|
|
|
$this->controller->webroot = $this->_webroot();
|
2006-01-12 02:10:47 +00:00
|
|
|
$this->controller->set(array('controller' => $className,
|
|
|
|
'action' => $action,
|
2006-01-13 23:53:23 +00:00
|
|
|
'file' => $file,
|
2006-01-12 02:10:47 +00:00
|
|
|
'title' => 'Missing View'));
|
2006-04-24 16:24:57 +00:00
|
|
|
$this->controller->render('missingView');
|
2006-03-16 01:50:55 +00:00
|
|
|
exit();
|
2006-01-12 02:10:47 +00:00
|
|
|
}
|
|
|
|
|
2006-01-13 23:53:23 +00:00
|
|
|
/**
|
|
|
|
* Renders the Missing Layout web page.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function missingLayout($params)
|
|
|
|
{
|
|
|
|
extract($params);
|
2006-04-24 16:24:57 +00:00
|
|
|
$this->controller->base = $base;
|
|
|
|
$this->controller->viewPath = 'errors';
|
2006-01-13 23:53:23 +00:00
|
|
|
$this->controller->webroot = $this->_webroot();
|
|
|
|
$this->controller->layout = 'default';
|
|
|
|
$this->controller->set(array('file' => $file,
|
|
|
|
'title' => 'Missing Layout'));
|
2006-04-24 16:24:57 +00:00
|
|
|
$this->controller->render('missingLayout');
|
2006-03-16 01:50:55 +00:00
|
|
|
exit();
|
2006-01-13 23:53:23 +00:00
|
|
|
}
|
|
|
|
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
|
|
|
* Renders the Missing Table web page.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function missingConnection($params)
|
|
|
|
{
|
|
|
|
extract($params);
|
2006-04-24 16:24:57 +00:00
|
|
|
$this->controller->viewPath = 'errors';
|
2006-01-12 02:10:47 +00:00
|
|
|
$this->controller->webroot = $this->_webroot();
|
|
|
|
$this->controller->set(array('model' => $className,
|
|
|
|
'title' => 'Missing Database Connection'));
|
2006-04-24 16:24:57 +00:00
|
|
|
$this->controller->render('missingConnection');
|
2006-01-12 02:10:47 +00:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2006-01-12 03:56:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the Missing Helper file web page.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function missingHelperFile($params)
|
|
|
|
{
|
|
|
|
extract($params);
|
2006-04-24 16:24:57 +00:00
|
|
|
$this->controller->base = $base;
|
|
|
|
$this->controller->viewPath = 'errors';
|
2006-01-13 23:53:23 +00:00
|
|
|
$this->controller->webroot = $this->_webroot();
|
|
|
|
$this->controller->set(array('helperClass' => Inflector::camelize($helper) . "Helper",
|
2006-01-12 03:56:59 +00:00
|
|
|
'file' => $file,
|
|
|
|
'title' => 'Missing Helper File'));
|
2006-04-24 16:24:57 +00:00
|
|
|
$this->controller->render('missingHelperFile');
|
2006-01-12 03:56:59 +00:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the Missing Helper class web page.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function missingHelperClass($params)
|
|
|
|
{
|
|
|
|
extract($params);
|
2006-04-24 16:24:57 +00:00
|
|
|
$this->controller->base = $base;
|
|
|
|
$this->controller->viewPath = 'errors';
|
2006-01-13 23:53:23 +00:00
|
|
|
$this->controller->webroot = $this->_webroot();
|
|
|
|
$this->controller->set(array('helperClass' => Inflector::camelize($helper) . "Helper",
|
|
|
|
'file' => $file,
|
2006-01-12 03:56:59 +00:00
|
|
|
'title' => 'Missing Helper Class'));
|
2006-04-24 16:24:57 +00:00
|
|
|
$this->controller->render('missingHelperClass');
|
2006-01-12 03:56:59 +00:00
|
|
|
exit();
|
|
|
|
}
|
2006-01-13 23:53:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the Missing Component file web page.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function missingComponentFile($params)
|
|
|
|
{
|
|
|
|
extract($params);
|
2006-04-24 16:24:57 +00:00
|
|
|
$this->controller->base = $base;
|
|
|
|
$this->controller->viewPath = 'errors';
|
2006-01-13 23:53:23 +00:00
|
|
|
$this->controller->webroot = $this->_webroot();
|
|
|
|
$this->controller->set(array('controller' => $className,
|
|
|
|
'component' => $component,
|
|
|
|
'file' => $file,
|
|
|
|
'title' => 'Missing Component File'));
|
2006-04-24 16:24:57 +00:00
|
|
|
$this->controller->render('missingComponentFile');
|
2006-01-13 23:53:23 +00:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the Missing Component class web page.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function missingComponentClass($params)
|
|
|
|
{
|
|
|
|
extract($params);
|
2006-04-24 16:24:57 +00:00
|
|
|
$this->controller->base = $base;
|
|
|
|
$this->controller->viewPath = 'errors';
|
2006-01-13 23:53:23 +00:00
|
|
|
$this->controller->webroot = $this->_webroot();
|
|
|
|
$this->controller->set(array('controller' => $className,
|
|
|
|
'component' => $component,
|
|
|
|
'file' => $file,
|
|
|
|
'title' => 'Missing Component Class'));
|
2006-04-24 16:24:57 +00:00
|
|
|
$this->controller->render('missingComponentClass');
|
2006-01-13 23:53:23 +00:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2006-02-01 13:26:23 +00:00
|
|
|
/**
|
|
|
|
* Renders the Missing Model class web page.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function missingModel($params)
|
|
|
|
{
|
|
|
|
extract($params);
|
2006-04-24 16:24:57 +00:00
|
|
|
$this->controller->base = $base;
|
|
|
|
$this->controller->viewPath = 'errors';
|
2006-02-01 13:26:23 +00:00
|
|
|
$this->controller->webroot = $this->_webroot();
|
|
|
|
$this->controller->set(array('model' => $className,
|
|
|
|
'title' => 'Missing Model'));
|
2006-04-24 16:24:57 +00:00
|
|
|
$this->controller->render('missingModel');
|
2006-02-01 13:26:23 +00:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-13 23:53:23 +00:00
|
|
|
|
2006-01-12 03:56:59 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2006-01-12 02:10:47 +00:00
|
|
|
function _webroot()
|
|
|
|
{
|
|
|
|
$dispatcher =& new Dispatcher();
|
|
|
|
$dispatcher->baseUrl();
|
|
|
|
return $dispatcher->webroot;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|