Base for a static organization website

exceptions.php 14KB

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