PageRenderTime 35ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/Cake/Error/exceptions.php

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