Exception.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Exception class
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  8. * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * Redistributions of files must retain the above copyright notice.
  12. *
  13. * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://book.cakephp.org/2.0/en/development/testing.html
  15. * @since CakePHP(tm) v 3.0
  16. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  17. */
  18. namespace Cake\Error;
  19. /**
  20. * Exception is used a base class for CakePHP's internal exceptions.
  21. * In general framework errors are interpreted as 500 code errors.
  22. *
  23. */
  24. class Exception extends BaseException {
  25. /**
  26. * Array of attributes that are passed in from the constructor, and
  27. * made available in the view when a development error is displayed.
  28. *
  29. * @var array
  30. */
  31. protected $_attributes = array();
  32. /**
  33. * Template string that has attributes sprintf()'ed into it.
  34. *
  35. * @var string
  36. */
  37. protected $_messageTemplate = '';
  38. /**
  39. * Constructor.
  40. *
  41. * Allows you to create exceptions that are treated as framework errors and disabled
  42. * when debug = 0.
  43. *
  44. * @param string|array $message Either the string of the error message, or an array of attributes
  45. * that are made available in the view, and sprintf()'d into Exception::$_messageTemplate
  46. * @param string $code The code of the error, is also the HTTP status code for the error.
  47. */
  48. public function __construct($message, $code = 500) {
  49. if (is_array($message)) {
  50. $this->_attributes = $message;
  51. $message = __d('cake_dev', $this->_messageTemplate, $message);
  52. }
  53. parent::__construct($message, $code);
  54. }
  55. /**
  56. * Get the passed in attributes
  57. *
  58. * @return array
  59. */
  60. public function getAttributes() {
  61. return $this->_attributes;
  62. }
  63. }