Exception.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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-2015 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  20. */
  21. /**
  22. * @category Zend
  23. * @package Zend
  24. * @copyright Copyright (c) 2005-2015 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. if (version_compare(PHP_VERSION, '5.3.0', '<')) {
  44. parent::__construct($msg, (int) $code);
  45. $this->_previous = $previous;
  46. } else {
  47. parent::__construct($msg, (int) $code, $previous);
  48. }
  49. }
  50. /**
  51. * Overloading
  52. *
  53. * For PHP < 5.3.0, provides access to the getPrevious() method.
  54. *
  55. * @param string $method
  56. * @param array $args
  57. * @return mixed
  58. */
  59. public function __call($method, array $args)
  60. {
  61. if ('getprevious' == strtolower($method)) {
  62. return $this->_getPrevious();
  63. }
  64. return null;
  65. }
  66. /**
  67. * String representation of the exception
  68. *
  69. * @return string
  70. */
  71. public function __toString()
  72. {
  73. if (version_compare(PHP_VERSION, '5.3.0', '<')) {
  74. if (null !== ($e = $this->getPrevious())) {
  75. return $e->__toString()
  76. . "\n\nNext "
  77. . parent::__toString();
  78. }
  79. }
  80. return parent::__toString();
  81. }
  82. /**
  83. * Returns previous Exception
  84. *
  85. * @return Exception|null
  86. */
  87. protected function _getPrevious()
  88. {
  89. return $this->_previous;
  90. }
  91. }