PageRenderTime 44ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

/cake/libs/error.php

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