PageRenderTime 42ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/cake/libs/error.php

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