Exception.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend
  17. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. */
  20. if (version_compare(PHP_VERSION, '5.3.0', '<')) {
  21. /**
  22. * @category Zend
  23. * @package Zend
  24. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  25. * @license http://framework.zend.com/license/new-bsd New BSD License
  26. */
  27. class Zend_Exception extends Exception
  28. {
  29. /**
  30. * @var null|Exception
  31. */
  32. private $_previous = null;
  33. /**
  34. * Construct the exception
  35. *
  36. * @param string $msg
  37. * @param int $code
  38. * @param Exception $previous
  39. * @return void
  40. */
  41. public function __construct($msg = '', $code = 0, Exception $previous = null)
  42. {
  43. parent::__construct($msg, (int) $code);
  44. $this->_previous = $previous;
  45. }
  46. /**
  47. * Returns previous Exception
  48. *
  49. * @return Exception|null
  50. */
  51. final public function getPrevious()
  52. {
  53. return $this->_previous;
  54. }
  55. /**
  56. * String representation of the exception
  57. *
  58. * @return string
  59. */
  60. public function __toString()
  61. {
  62. if (null !== ($e = $this->getPrevious())) {
  63. return $e->__toString()
  64. . "\n\nNext "
  65. . parent::__toString();
  66. }
  67. return parent::__toString();
  68. }
  69. }
  70. } else {
  71. /**
  72. * @category Zend
  73. * @package Zend
  74. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  75. * @license http://framework.zend.com/license/new-bsd New BSD License
  76. */
  77. class Zend_Exception extends Exception
  78. {
  79. public function __construct($msg = '', $code = 0, Exception $previous = null)
  80. {
  81. if (!is_int($code)) {
  82. $code = (int) $code;
  83. }
  84. parent::__construct($msg, $code, $previous);
  85. }
  86. }
  87. }