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

/lib/Cake/Error/exceptions.php

https://bitbucket.org/udeshika/fake_twitter
PHP | 450 lines | 140 code | 41 blank | 269 comment | 8 complexity | f94fa2dd13db73536fc3b8c1234bf316 MD5 | raw file
  1. <?php
  2. /**
  3. * Exceptions file. Contains the various exceptions CakePHP will throw until they are
  4. * moved into their permanent location.
  5. *
  6. * PHP 5
  7. *
  8. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  9. * Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
  10. *
  11. * Licensed under The MIT License
  12. * Redistributions of files must retain the above copyright notice.
  13. *
  14. * @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
  15. * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
  16. * @package Cake.Error
  17. * @since CakePHP(tm) v 2.0
  18. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  19. */
  20. /**
  21. * Parent class for all of the HTTP related exceptions in CakePHP.
  22. * All HTTP status/error related exceptions should extend this class so
  23. * catch blocks can be specifically typed.
  24. *
  25. * @package Cake.Error
  26. */
  27. if (!class_exists('HttpException')) {
  28. class HttpException extends RuntimeException { }
  29. }
  30. /**
  31. * Represents an HTTP 400 error.
  32. *
  33. * @package Cake.Error
  34. */
  35. class BadRequestException extends HttpException {
  36. /**
  37. * Constructor
  38. *
  39. * @param string $message If no message is given 'Bad Request' will be the message
  40. * @param string $code Status code, defaults to 400
  41. */
  42. public function __construct($message = null, $code = 400) {
  43. if (empty($message)) {
  44. $message = 'Bad Request';
  45. }
  46. parent::__construct($message, $code);
  47. }
  48. }
  49. /**
  50. * Represents an HTTP 401 error.
  51. *
  52. * @package Cake.Error
  53. */
  54. class UnauthorizedException extends HttpException {
  55. /**
  56. * Constructor
  57. *
  58. * @param string $message If no message is given 'Unauthorized' will be the message
  59. * @param string $code Status code, defaults to 401
  60. */
  61. public function __construct($message = null, $code = 401) {
  62. if (empty($message)) {
  63. $message = 'Unauthorized';
  64. }
  65. parent::__construct($message, $code);
  66. }
  67. }
  68. /**
  69. * Represents an HTTP 403 error.
  70. *
  71. * @package Cake.Error
  72. */
  73. class ForbiddenException extends HttpException {
  74. /**
  75. * Constructor
  76. *
  77. * @param string $message If no message is given 'Forbidden' will be the message
  78. * @param string $code Status code, defaults to 403
  79. */
  80. public function __construct($message = null, $code = 403) {
  81. if (empty($message)) {
  82. $message = 'Forbidden';
  83. }
  84. parent::__construct($message, $code);
  85. }
  86. }
  87. /**
  88. * Represents an HTTP 404 error.
  89. *
  90. * @package Cake.Error
  91. */
  92. class NotFoundException extends HttpException {
  93. /**
  94. * Constructor
  95. *
  96. * @param string $message If no message is given 'Not Found' will be the message
  97. * @param string $code Status code, defaults to 404
  98. */
  99. public function __construct($message = null, $code = 404) {
  100. if (empty($message)) {
  101. $message = 'Not Found';
  102. }
  103. parent::__construct($message, $code);
  104. }
  105. }
  106. /**
  107. * Represents an HTTP 405 error.
  108. *
  109. * @package Cake.Error
  110. */
  111. class MethodNotAllowedException extends HttpException {
  112. /**
  113. * Constructor
  114. *
  115. * @param string $message If no message is given 'Method Not Allowed' will be the message
  116. * @param string $code Status code, defaults to 405
  117. */
  118. public function __construct($message = null, $code = 405) {
  119. if (empty($message)) {
  120. $message = 'Method Not Allowed';
  121. }
  122. parent::__construct($message, $code);
  123. }
  124. }
  125. /**
  126. * Represents an HTTP 500 error.
  127. *
  128. * @package Cake.Error
  129. */
  130. class InternalErrorException extends HttpException {
  131. /**
  132. * Constructor
  133. *
  134. * @param string $message If no message is given 'Internal Server Error' will be the message
  135. * @param string $code Status code, defaults to 500
  136. */
  137. public function __construct($message = null, $code = 500) {
  138. if (empty($message)) {
  139. $message = 'Internal Server Error';
  140. }
  141. parent::__construct($message, $code);
  142. }
  143. }
  144. /**
  145. * CakeException is used a base class for CakePHP's internal exceptions.
  146. * In general framework errors are interpreted as 500 code errors.
  147. *
  148. * @package Cake.Error
  149. */
  150. class CakeException extends RuntimeException {
  151. /**
  152. * Array of attributes that are passed in from the constructor, and
  153. * made available in the view when a development error is displayed.
  154. *
  155. * @var array
  156. */
  157. protected $_attributes = array();
  158. /**
  159. * Template string that has attributes sprintf()'ed into it.
  160. *
  161. * @var string
  162. */
  163. protected $_messageTemplate = '';
  164. /**
  165. * Constructor.
  166. *
  167. * Allows you to create exceptions that are treated as framework errors and disabled
  168. * when debug = 0.
  169. *
  170. * @param mixed $message Either the string of the error message, or an array of attributes
  171. * that are made available in the view, and sprintf()'d into CakeException::$_messageTemplate
  172. * @param string $code The code of the error, is also the HTTP status code for the error.
  173. */
  174. public function __construct($message, $code = 500) {
  175. if (is_array($message)) {
  176. $this->_attributes = $message;
  177. $message = __d('cake_dev', $this->_messageTemplate, $message);
  178. }
  179. parent::__construct($message, $code);
  180. }
  181. /**
  182. * Get the passed in attributes
  183. *
  184. * @return array
  185. */
  186. public function getAttributes() {
  187. return $this->_attributes;
  188. }
  189. }
  190. /**
  191. * Missing Controller exception - used when a controller
  192. * cannot be found.
  193. *
  194. * @package Cake.Error
  195. */
  196. class MissingControllerException extends CakeException {
  197. protected $_messageTemplate = 'Controller class %s could not be found.';
  198. public function __construct($message, $code = 404) {
  199. parent::__construct($message, $code);
  200. }
  201. }
  202. /**
  203. * Missing Action exception - used when a controller action
  204. * cannot be found.
  205. *
  206. * @package Cake.Error
  207. */
  208. class MissingActionException extends CakeException {
  209. protected $_messageTemplate = 'Action %s::%s() could not be found.';
  210. public function __construct($message, $code = 404) {
  211. parent::__construct($message, $code);
  212. }
  213. }
  214. /**
  215. * Private Action exception - used when a controller action
  216. * starts with a `_`.
  217. *
  218. * @package Cake.Error
  219. */
  220. class PrivateActionException extends CakeException {
  221. protected $_messageTemplate = 'Private Action %s::%s() is not directly accessible.';
  222. public function __construct($message, $code = 404, Exception $previous = null) {
  223. parent::__construct($message, $code, $previous);
  224. }
  225. }
  226. /**
  227. * Used when a component cannot be found.
  228. *
  229. * @package Cake.Error
  230. */
  231. class MissingComponentException extends CakeException {
  232. protected $_messageTemplate = 'Component class %s could not be found.';
  233. }
  234. /**
  235. * Used when a behavior cannot be found.
  236. *
  237. * @package Cake.Error
  238. */
  239. class MissingBehaviorException extends CakeException {
  240. protected $_messageTemplate = 'Behavior class %s could not be found.';
  241. }
  242. /**
  243. * Used when a view file cannot be found.
  244. *
  245. * @package Cake.Error
  246. */
  247. class MissingViewException extends CakeException {
  248. protected $_messageTemplate = 'View file "%s" is missing.';
  249. }
  250. /**
  251. * Used when a layout file cannot be found.
  252. *
  253. * @package Cake.Error
  254. */
  255. class MissingLayoutException extends CakeException {
  256. protected $_messageTemplate = 'Layout file "%s" is missing.';
  257. }
  258. /**
  259. * Used when a helper cannot be found.
  260. *
  261. * @package Cake.Error
  262. */
  263. class MissingHelperException extends CakeException {
  264. protected $_messageTemplate = 'Helper class %s could not be found.';
  265. }
  266. /**
  267. * Runtime Exceptions for ConnectionManager
  268. *
  269. * @package Cake.Error
  270. */
  271. class MissingDatabaseException extends CakeException {
  272. protected $_messageTemplate = 'Database connection "%s" could not be found.';
  273. }
  274. /**
  275. * Used when no connections can be found.
  276. *
  277. * @package Cake.Error
  278. */
  279. class MissingConnectionException extends CakeException {
  280. protected $_messageTemplate = 'Database connection "%s" is missing, or could not be created.';
  281. }
  282. /**
  283. * Used when a Task cannot be found.
  284. *
  285. * @package Cake.Error
  286. */
  287. class MissingTaskException extends CakeException {
  288. protected $_messageTemplate = 'Task class %s could not be found.';
  289. }
  290. /**
  291. * Used when a shell method cannot be found.
  292. *
  293. * @package Cake.Error
  294. */
  295. class MissingShellMethodException extends CakeException {
  296. protected $_messageTemplate = "Unknown command %1\$s %2\$s.\nFor usage try `cake %1\$s --help`";
  297. }
  298. /**
  299. * Used when a shell cannot be found.
  300. *
  301. * @package Cake.Error
  302. */
  303. class MissingShellException extends CakeException {
  304. protected $_messageTemplate = 'Shell class %s could not be found.';
  305. }
  306. /**
  307. * Exception class to be thrown when a datasource configuration is not found
  308. *
  309. * @package Cake.Error
  310. */
  311. class MissingDatasourceConfigException extends CakeException {
  312. protected $_messageTemplate = 'The datasource configuration "%s" was not found in database.php';
  313. }
  314. /**
  315. * Used when a datasource cannot be found.
  316. *
  317. * @package Cake.Error
  318. */
  319. class MissingDatasourceException extends CakeException {
  320. protected $_messageTemplate = 'Datasource class %s could not be found.';
  321. }
  322. /**
  323. * Exception class to be thrown when a database table is not found in the datasource
  324. *
  325. * @package Cake.Error
  326. */
  327. class MissingTableException extends CakeException {
  328. protected $_messageTemplate = 'Database table %s for model %s was not found.';
  329. }
  330. /**
  331. * Exception raised when a Model could not be found.
  332. *
  333. * @package Cake.Error
  334. */
  335. class MissingModelException extends CakeException {
  336. protected $_messageTemplate = 'Model %s could not be found.';
  337. }
  338. /**
  339. * Exception raised when a test loader could not be found
  340. *
  341. * @package Cake.Error
  342. */
  343. class MissingTestLoaderException extends CakeException {
  344. protected $_messageTemplate = 'Test loader %s could not be found.';
  345. }
  346. /**
  347. * Exception raised when a plugin could not be found
  348. *
  349. * @package Cake.Error
  350. */
  351. class MissingPluginException extends CakeException {
  352. protected $_messageTemplate = 'Plugin %s could not be found.';
  353. }
  354. /**
  355. * Exception class for Cache. This exception will be thrown from Cache when it
  356. * encounters an error.
  357. *
  358. * @package Cake.Error
  359. */
  360. class CacheException extends CakeException { }
  361. /**
  362. * Exception class for Router. This exception will be thrown from Router when it
  363. * encounters an error.
  364. *
  365. * @package Cake.Error
  366. */
  367. class RouterException extends CakeException { }
  368. /**
  369. * Exception class for CakeLog. This exception will be thrown from CakeLog when it
  370. * encounters an error.
  371. *
  372. * @package Cake.Error
  373. */
  374. class CakeLogException extends CakeException { }
  375. /**
  376. * Exception class for CakeSession. This exception will be thrown from CakeSession when it
  377. * encounters an error.
  378. *
  379. * @package Cake.Error
  380. */
  381. class CakeSessionException extends CakeException { }
  382. /**
  383. * Exception class for Configure. This exception will be thrown from Configure when it
  384. * encounters an error.
  385. *
  386. * @package Cake.Error
  387. */
  388. class ConfigureException extends CakeException { }
  389. /**
  390. * Exception class for Socket. This exception will be thrown from CakeSocket, CakeEmail, HttpSocket
  391. * SmtpTransport, MailTransport and HttpResponse when it encounters an error.
  392. *
  393. * @package Cake.Error
  394. */
  395. class SocketException extends CakeException { }
  396. /**
  397. * Exception class for Xml. This exception will be thrown from Xml when it
  398. * encounters an error.
  399. *
  400. * @package Cake.Error
  401. */
  402. class XmlException extends CakeException { }
  403. /**
  404. * Exception class for Console libraries. This exception will be thrown from Console library
  405. * classes when they encounter an error.
  406. *
  407. * @package Cake.Error
  408. */
  409. class ConsoleException extends CakeException { }