exceptions.php 11 KB

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