PageRenderTime 51ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/cake/libs/error.php

https://github.com/MrRio/wildflower
PHP | 378 lines | 198 code | 19 blank | 161 comment | 13 complexity | da7d3c6fa0705699051577d525f9e3b8 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /* SVN FILE: $Id: error.php 8004 2009-01-16 20:15:21Z gwoo $ */
  3. /**
  4. * Error handler
  5. *
  6. * Provides Error Capturing for Framework errors.
  7. *
  8. * PHP versions 4 and 5
  9. *
  10. * CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
  11. * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
  12. *
  13. * Licensed under The MIT License
  14. * Redistributions of files must retain the above copyright notice.
  15. *
  16. * @filesource
  17. * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
  18. * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
  19. * @package cake
  20. * @subpackage cake.cake.libs
  21. * @since CakePHP(tm) v 0.10.5.1732
  22. * @version $Revision: 8004 $
  23. * @modifiedby $LastChangedBy: gwoo $
  24. * @lastmodified $Date: 2009-01-16 12:15:21 -0800 (Fri, 16 Jan 2009) $
  25. * @license http://www.opensource.org/licenses/mit-license.php The MIT License
  26. */
  27. App::import('Controller', 'App');
  28. /**
  29. * Error Handling Controller
  30. *
  31. * Controller used by ErrorHandler to render error views.
  32. *
  33. * @package cake
  34. * @subpackage cake.cake.libs
  35. */
  36. class CakeErrorController extends AppController {
  37. var $name = 'CakeError';
  38. /**
  39. * Uses Property
  40. *
  41. * @var array
  42. */
  43. var $uses = array();
  44. /**
  45. * __construct
  46. *
  47. * @access public
  48. * @return void
  49. */
  50. function __construct() {
  51. parent::__construct();
  52. $this->_set(Router::getPaths());
  53. $this->params = Router::getParams();
  54. $this->constructClasses();
  55. $this->Component->initialize($this);
  56. $this->_set(array('cacheAction' => false, 'viewPath' => 'errors'));
  57. }
  58. }
  59. /**
  60. * Error Handler.
  61. *
  62. * Captures and handles all cakeError() calls.
  63. * Displays helpful framework errors when debug > 1.
  64. * When debug < 1 cakeError() will render 404 or 500 errors.
  65. *
  66. * @package cake
  67. * @subpackage cake.cake.libs
  68. */
  69. class ErrorHandler extends Object {
  70. /**
  71. * Controller instance.
  72. *
  73. * @var object
  74. * @access public
  75. */
  76. var $controller = null;
  77. /**
  78. * Class constructor.
  79. *
  80. * @param string $method Method producing the error
  81. * @param array $messages Error messages
  82. */
  83. function __construct($method, $messages) {
  84. App::import('Core', 'Sanitize');
  85. static $__previousError = null;
  86. if ($__previousError != array($method, $messages)) {
  87. $__previousError = array($method, $messages);
  88. $this->controller =& new CakeErrorController();
  89. } else {
  90. $this->controller =& new Controller();
  91. $this->controller->viewPath = 'errors';
  92. }
  93. $options = array('escape' => false);
  94. $messages = Sanitize::clean($messages, $options);
  95. if (!isset($messages[0])) {
  96. $messages = array($messages);
  97. }
  98. if (method_exists($this->controller, 'apperror')) {
  99. return $this->controller->appError($method, $messages);
  100. }
  101. if (!in_array(strtolower($method), array_map('strtolower', get_class_methods($this)))) {
  102. $method = 'error';
  103. }
  104. if ($method !== 'error') {
  105. if (Configure::read() == 0) {
  106. $method = 'error404';
  107. if (isset($code) && $code == 500) {
  108. $method = 'error500';
  109. }
  110. }
  111. }
  112. $this->dispatchMethod($method, $messages);
  113. $this->_stop();
  114. }
  115. /**
  116. * Displays an error page (e.g. 404 Not found).
  117. *
  118. * @param array $params Parameters for controller
  119. * @access public
  120. */
  121. function error($params) {
  122. extract($params, EXTR_OVERWRITE);
  123. $this->controller->set(array(
  124. 'code' => $code,
  125. 'name' => $name,
  126. 'message' => $message,
  127. 'title' => $code . ' ' . $name
  128. ));
  129. $this->_outputMessage('error404');
  130. }
  131. /**
  132. * Convenience method to display a 404 page.
  133. *
  134. * @param array $params Parameters for controller
  135. * @access public
  136. */
  137. function error404($params) {
  138. extract($params, EXTR_OVERWRITE);
  139. if (!isset($url)) {
  140. $url = $this->controller->here;
  141. }
  142. $url = Router::normalize($url);
  143. header("HTTP/1.0 404 Not Found");
  144. $this->controller->set(array(
  145. 'code' => '404',
  146. 'name' => __('Not Found', true),
  147. 'message' => $url,
  148. 'base' => $this->controller->base
  149. ));
  150. $this->_outputMessage('error404');
  151. }
  152. /**
  153. * Renders the Missing Controller web page.
  154. *
  155. * @param array $params Parameters for controller
  156. * @access public
  157. */
  158. function missingController($params) {
  159. extract($params, EXTR_OVERWRITE);
  160. $controllerName = str_replace('Controller', '', $className);
  161. $this->controller->set(array(
  162. 'controller' => $className,
  163. 'controllerName' => $controllerName,
  164. 'title' => __('Missing Controller', true)
  165. ));
  166. $this->_outputMessage('missingController');
  167. }
  168. /**
  169. * Renders the Missing Action web page.
  170. *
  171. * @param array $params Parameters for controller
  172. * @access public
  173. */
  174. function missingAction($params) {
  175. extract($params, EXTR_OVERWRITE);
  176. $controllerName = str_replace('Controller', '', $className);
  177. $this->controller->set(array(
  178. 'controller' => $className,
  179. 'controllerName' => $controllerName,
  180. 'action' => $action,
  181. 'title' => __('Missing Method in Controller', true)
  182. ));
  183. $this->_outputMessage('missingAction');
  184. }
  185. /**
  186. * Renders the Private Action web page.
  187. *
  188. * @param array $params Parameters for controller
  189. * @access public
  190. */
  191. function privateAction($params) {
  192. extract($params, EXTR_OVERWRITE);
  193. $this->controller->set(array(
  194. 'controller' => $className,
  195. 'action' => $action,
  196. 'title' => __('Trying to access private method in class', true)
  197. ));
  198. $this->_outputMessage('privateAction');
  199. }
  200. /**
  201. * Renders the Missing Table web page.
  202. *
  203. * @param array $params Parameters for controller
  204. * @access public
  205. */
  206. function missingTable($params) {
  207. extract($params, EXTR_OVERWRITE);
  208. $this->controller->set(array(
  209. 'model' => $className,
  210. 'table' => $table,
  211. 'title' => __('Missing Database Table', true)
  212. ));
  213. $this->_outputMessage('missingTable');
  214. }
  215. /**
  216. * Renders the Missing Database web page.
  217. *
  218. * @param array $params Parameters for controller
  219. * @access public
  220. */
  221. function missingDatabase($params = array()) {
  222. $this->controller->set(array(
  223. 'title' => __('Scaffold Missing Database Connection', true)
  224. ));
  225. $this->_outputMessage('missingScaffolddb');
  226. }
  227. /**
  228. * Renders the Missing View web page.
  229. *
  230. * @param array $params Parameters for controller
  231. * @access public
  232. */
  233. function missingView($params) {
  234. extract($params, EXTR_OVERWRITE);
  235. $this->controller->set(array(
  236. 'controller' => $className,
  237. 'action' => $action,
  238. 'file' => $file,
  239. 'title' => __('Missing View', true)
  240. ));
  241. $this->_outputMessage('missingView');
  242. }
  243. /**
  244. * Renders the Missing Layout web page.
  245. *
  246. * @param array $params Parameters for controller
  247. * @access public
  248. */
  249. function missingLayout($params) {
  250. extract($params, EXTR_OVERWRITE);
  251. $this->controller->layout = 'default';
  252. $this->controller->set(array(
  253. 'file' => $file,
  254. 'title' => __('Missing Layout', true)
  255. ));
  256. $this->_outputMessage('missingLayout');
  257. }
  258. /**
  259. * Renders the Database Connection web page.
  260. *
  261. * @param array $params Parameters for controller
  262. * @access public
  263. */
  264. function missingConnection($params) {
  265. extract($params, EXTR_OVERWRITE);
  266. $this->controller->set(array(
  267. 'model' => $className,
  268. 'title' => __('Missing Database Connection', true)
  269. ));
  270. $this->_outputMessage('missingConnection');
  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($params, EXTR_OVERWRITE);
  280. $this->controller->set(array(
  281. 'helperClass' => Inflector::camelize($helper) . "Helper",
  282. 'file' => $file,
  283. 'title' => __('Missing Helper File', true)
  284. ));
  285. $this->_outputMessage('missingHelperFile');
  286. }
  287. /**
  288. * Renders the Missing Helper class web page.
  289. *
  290. * @param array $params Parameters for controller
  291. * @access public
  292. */
  293. function missingHelperClass($params) {
  294. extract($params, EXTR_OVERWRITE);
  295. $this->controller->set(array(
  296. 'helperClass' => Inflector::camelize($helper) . "Helper",
  297. 'file' => $file,
  298. 'title' => __('Missing Helper Class', true)
  299. ));
  300. $this->_outputMessage('missingHelperClass');
  301. }
  302. /**
  303. * Renders the Missing Component file web page.
  304. *
  305. * @param array $params Parameters for controller
  306. * @access public
  307. */
  308. function missingComponentFile($params) {
  309. extract($params, EXTR_OVERWRITE);
  310. $this->controller->set(array(
  311. 'controller' => $className,
  312. 'component' => $component,
  313. 'file' => $file,
  314. 'title' => __('Missing Component File', true)
  315. ));
  316. $this->_outputMessage('missingComponentFile');
  317. }
  318. /**
  319. * Renders the Missing Component class web page.
  320. *
  321. * @param array $params Parameters for controller
  322. * @access public
  323. */
  324. function missingComponentClass($params) {
  325. extract($params, EXTR_OVERWRITE);
  326. $this->controller->set(array(
  327. 'controller' => $className,
  328. 'component' => $component,
  329. 'file' => $file,
  330. 'title' => __('Missing Component Class', true)
  331. ));
  332. $this->_outputMessage('missingComponentClass');
  333. }
  334. /**
  335. * Renders the Missing Model class web page.
  336. *
  337. * @param unknown_type $params Parameters for controller
  338. * @access public
  339. */
  340. function missingModel($params) {
  341. extract($params, EXTR_OVERWRITE);
  342. $this->controller->set(array(
  343. 'model' => $className,
  344. 'title' => __('Missing Model', true)
  345. ));
  346. $this->_outputMessage('missingModel');
  347. }
  348. /**
  349. * Output message
  350. *
  351. * @access protected
  352. */
  353. function _outputMessage($template) {
  354. $this->controller->render($template);
  355. $this->controller->afterFilter();
  356. echo $this->controller->output;
  357. }
  358. }
  359. ?>