PageRenderTime 64ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/department/cake/libs/error.php

https://github.com/adivik2000/nigraha
PHP | 394 lines | 345 code | 2 blank | 47 comment | 2 complexity | 70267d251f784089781bda97bb6750fd MD5 | raw file
  1. <?php
  2. /* SVN FILE: $Id: error.php 5811 2007-10-20 06:39:14Z 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: 5811 $
  25. * @modifiedby $LastChangedBy: phpnut $
  26. * @lastmodified $Date: 2007-10-20 01:39:14 -0500 (Sat, 20 Oct 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. /**
  40. * Controller instance.
  41. *
  42. * @var object
  43. * @access public
  44. */
  45. var $controller = null;
  46. /**
  47. * Class constructor.
  48. *
  49. * @param string $method Method producing the error
  50. * @param array $messages Error messages
  51. */
  52. function __construct($method, $messages) {
  53. parent::__construct();
  54. static $__previousError = null;
  55. $allow = array('.', '/', '_', ' ', '-', '~');
  56. if (substr(PHP_OS,0,3) == "WIN") {
  57. $allow = array_merge($allow, array('\\', ':') );
  58. }
  59. $clean = new Sanitize();
  60. $messages = $clean->paranoid($messages, $allow);
  61. if (!class_exists('dispatcher')) {
  62. require CAKE . 'dispatcher.php';
  63. }
  64. $this->__dispatch =& new Dispatcher();
  65. if (!class_exists('appcontroller')) {
  66. loadController(null);
  67. }
  68. if ($__previousError != array($method, $messages)) {
  69. $__previousError = array($method, $messages);
  70. $this->controller =& new AppController();
  71. if (!empty($this->controller->uses)) {
  72. $this->controller->constructClasses();
  73. }
  74. $this->controller->_initComponents();
  75. $this->controller->cacheAction = false;
  76. $this->__dispatch->start($this->controller);
  77. if (method_exists($this->controller, 'apperror')) {
  78. return $this->controller->appError($method, $messages);
  79. }
  80. } else {
  81. $this->controller =& new AppController();
  82. $this->controller->cacheAction = false;
  83. }
  84. if (Configure::read() > 0 || $method == 'error') {
  85. call_user_func_array(array(&$this, $method), $messages);
  86. } else {
  87. call_user_func_array(array(&$this, 'error404'), $messages);
  88. }
  89. }
  90. /**
  91. * Displays an error page (e.g. 404 Not found).
  92. *
  93. * @param array $params Parameters for controller
  94. * @access public
  95. */
  96. function error($params) {
  97. extract($params);
  98. $this->controller->base = $base;
  99. $this->controller->webroot = $this->_webroot();
  100. $this->controller->viewPath='errors';
  101. $this->controller->set(array('code' => $code,
  102. 'name' => $name,
  103. 'message' => $message,
  104. 'title' => $code . ' ' . $name));
  105. $this->controller->render('error404');
  106. exit();
  107. }
  108. /**
  109. * Convenience method to display a 404 page.
  110. *
  111. * @param array $params Parameters for controller
  112. * @access public
  113. */
  114. function error404($params) {
  115. extract($params);
  116. if (!isset($url)) {
  117. $url = $action;
  118. }
  119. if (!isset($message)) {
  120. $message = '';
  121. }
  122. if (!isset($base)) {
  123. $base = '';
  124. }
  125. header("HTTP/1.0 404 Not Found");
  126. $this->error(array('code' => '404',
  127. 'name' => __('Not found', true),
  128. 'message' => sprintf(__("The requested address %s was not found on this server.", true), $url, $message),
  129. 'base' => $base));
  130. exit();
  131. }
  132. /**
  133. * Renders the Missing Controller web page.
  134. *
  135. * @param array $params Parameters for controller
  136. * @access public
  137. */
  138. function missingController($params) {
  139. extract(Router::getPaths());
  140. extract($params, EXTR_OVERWRITE);
  141. $this->controller->base = $base;
  142. $this->controller->webroot = $webroot;
  143. $this->controller->viewPath ='errors';
  144. $controllerName = str_replace('Controller', '', $className);
  145. $this->controller->set(array('controller' => $className,
  146. 'controllerName' => $controllerName,
  147. 'title' => __('Missing Controller', true)));
  148. $this->controller->render('missingController');
  149. exit();
  150. }
  151. /**
  152. * Renders the Missing Action web page.
  153. *
  154. * @param array $params Parameters for controller
  155. * @access public
  156. */
  157. function missingAction($params) {
  158. extract(Router::getPaths());
  159. extract($params, EXTR_OVERWRITE);
  160. $this->controller->base = $base;
  161. $this->controller->webroot = $webroot;
  162. $this->controller->viewPath = 'errors';
  163. $this->controller->set(array('controller' => $className,
  164. 'action' => $action,
  165. 'title' => __('Missing Method in Controller', true)));
  166. $this->controller->render('missingAction');
  167. exit();
  168. }
  169. /**
  170. * Renders the Private Action web page.
  171. *
  172. * @param array $params Parameters for controller
  173. * @access public
  174. */
  175. function privateAction($params) {
  176. extract(Router::getPaths());
  177. extract($params, EXTR_OVERWRITE);
  178. $this->controller->base = $base;
  179. $this->controller->webroot = $webroot;
  180. $this->controller->viewPath = 'errors';
  181. $this->controller->set(array('controller' => $className,
  182. 'action' => $action,
  183. 'title' => __('Trying to access private method in class', true)));
  184. $this->controller->render('privateAction');
  185. exit();
  186. }
  187. /**
  188. * Renders the Missing Table web page.
  189. *
  190. * @param array $params Parameters for controller
  191. * @access public
  192. */
  193. function missingTable($params) {
  194. extract(Router::getPaths());
  195. extract($params, EXTR_OVERWRITE);
  196. $this->controller->viewPath = 'errors';
  197. $this->controller->webroot = $this->_webroot();
  198. $this->controller->set(array('model' => $className,
  199. 'table' => $table,
  200. 'title' => __('Missing Database Table', true)));
  201. $this->controller->render('missingTable');
  202. exit();
  203. }
  204. /**
  205. * Renders the Missing Database web page.
  206. *
  207. * @param array $params Parameters for controller
  208. * @access public
  209. */
  210. function missingDatabase($params = array()) {
  211. extract(Router::getPaths());
  212. extract($params, EXTR_OVERWRITE);
  213. $this->controller->viewPath = 'errors';
  214. $this->controller->webroot = $this->_webroot();
  215. $this->controller->set(array('title' => __('Scaffold Missing Database Connection', true)));
  216. $this->controller->render('missingScaffolddb');
  217. exit();
  218. }
  219. /**
  220. * Renders the Missing View web page.
  221. *
  222. * @param array $params Parameters for controller
  223. * @access public
  224. */
  225. function missingView($params) {
  226. extract(Router::getPaths());
  227. extract($params, EXTR_OVERWRITE);
  228. $this->controller->base = $base;
  229. $this->controller->viewPath = 'errors';
  230. $this->controller->webroot = $this->_webroot();
  231. $this->controller->set(array('controller' => $className,
  232. 'action' => $action,
  233. 'file' => $file,
  234. 'title' => __('Missing View', true)));
  235. $this->controller->render('missingView');
  236. exit();
  237. }
  238. /**
  239. * Renders the Missing Layout web page.
  240. *
  241. * @param array $params Parameters for controller
  242. * @access public
  243. */
  244. function missingLayout($params) {
  245. extract(Router::getPaths());
  246. extract($params, EXTR_OVERWRITE);
  247. $this->controller->base = $base;
  248. $this->controller->viewPath = 'errors';
  249. $this->controller->webroot = $this->_webroot();
  250. $this->controller->layout = 'default';
  251. $this->controller->set(array('file' => $file,
  252. 'title' => __('Missing Layout', true)));
  253. $this->controller->render('missingLayout');
  254. exit();
  255. }
  256. /**
  257. * Renders the Database Connection web page.
  258. *
  259. * @param array $params Parameters for controller
  260. * @access public
  261. */
  262. function missingConnection($params) {
  263. extract(Router::getPaths());
  264. extract($params, EXTR_OVERWRITE);
  265. $this->controller->viewPath = 'errors';
  266. $this->controller->webroot = $this->_webroot();
  267. $this->controller->set(array('model' => $className,
  268. 'title' => __('Missing Database Connection', true)));
  269. $this->controller->render('missingConnection');
  270. exit();
  271. }
  272. /**
  273. * Renders the Missing Helper file web page.
  274. *
  275. * @param array $params Parameters for controller
  276. * @access public
  277. */
  278. function missingHelperFile($params) {
  279. extract(Router::getPaths());
  280. extract($params, EXTR_OVERWRITE);
  281. $this->controller->base = $base;
  282. $this->controller->viewPath = 'errors';
  283. $this->controller->webroot = $this->_webroot();
  284. $this->controller->set(array('helperClass' => Inflector::camelize($helper) . "Helper",
  285. 'file' => $file,
  286. 'title' => __('Missing Helper File', true)));
  287. $this->controller->render('missingHelperFile');
  288. exit();
  289. }
  290. /**
  291. * Renders the Missing Helper class web page.
  292. *
  293. * @param array $params Parameters for controller
  294. * @access public
  295. */
  296. function missingHelperClass($params) {
  297. extract(Router::getPaths());
  298. extract($params, EXTR_OVERWRITE);
  299. $this->controller->base = $base;
  300. $this->controller->viewPath = 'errors';
  301. $this->controller->webroot = $this->_webroot();
  302. $this->controller->set(array('helperClass' => Inflector::camelize($helper) . "Helper",
  303. 'file' => $file,
  304. 'title' => __('Missing Helper Class', true)));
  305. $this->controller->render('missingHelperClass');
  306. exit();
  307. }
  308. /**
  309. * Renders the Missing Component file web page.
  310. *
  311. * @param array $params Parameters for controller
  312. * @access public
  313. */
  314. function missingComponentFile($params) {
  315. extract(Router::getPaths());
  316. extract($params, EXTR_OVERWRITE);
  317. $this->controller->base = $base;
  318. $this->controller->viewPath = 'errors';
  319. $this->controller->webroot = $this->_webroot();
  320. $this->controller->set(array('controller' => $className,
  321. 'component' => $component,
  322. 'file' => $file,
  323. 'title' => __('Missing Component File', true)));
  324. $this->controller->render('missingComponentFile');
  325. exit();
  326. }
  327. /**
  328. * Renders the Missing Component class web page.
  329. *
  330. * @param array $params Parameters for controller
  331. * @access public
  332. */
  333. function missingComponentClass($params) {
  334. extract(Router::getPaths());
  335. extract($params, EXTR_OVERWRITE);
  336. $this->controller->base = $base;
  337. $this->controller->viewPath = 'errors';
  338. $this->controller->webroot = $this->_webroot();
  339. $this->controller->set(array('controller' => $className,
  340. 'component' => $component,
  341. 'file' => $file,
  342. 'title' => __('Missing Component Class', true)));
  343. $this->controller->render('missingComponentClass');
  344. exit();
  345. }
  346. /**
  347. * Renders the Missing Model class web page.
  348. *
  349. * @param unknown_type $params Parameters for controller
  350. * @access public
  351. */
  352. function missingModel($params) {
  353. extract(Router::getPaths());
  354. extract($params, EXTR_OVERWRITE);
  355. $this->controller->base = $base;
  356. $this->controller->viewPath = 'errors';
  357. $this->controller->webroot = $this->_webroot();
  358. $this->controller->set(array('model' => $className,
  359. 'title' => __('Missing Model', true)));
  360. $this->controller->render('missingModel');
  361. exit();
  362. }
  363. /**
  364. * Path to the web root.
  365. *
  366. * @return string full web root path
  367. * @access private
  368. */
  369. function _webroot() {
  370. $this->__dispatch->baseUrl();
  371. return $this->__dispatch->webroot;
  372. }
  373. }
  374. ?>