File indexing completed on 2024-12-22 05:37:16

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend
0017  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0018  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0019  * @version    $Id$
0020  */
0021 
0022 /**
0023 * @category   Zend
0024 * @package    Zend
0025 * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0026 * @license    http://framework.zend.com/license/new-bsd     New BSD License
0027 */
0028 class Zend_Exception extends Exception
0029 {
0030     /**
0031      * @var null|Exception
0032      */
0033     private $_previous = null;
0034 
0035     /**
0036      * Construct the exception
0037      *
0038      * @param  string $msg
0039      * @param  int $code
0040      * @param  Exception $previous
0041      * @return void
0042      */
0043     public function __construct($msg = '', $code = 0, Exception $previous = null)
0044     {
0045         if (version_compare(PHP_VERSION, '5.3.0', '<')) {
0046             parent::__construct($msg, (int) $code);
0047             $this->_previous = $previous;
0048         } else {
0049             parent::__construct($msg, (int) $code, $previous);
0050         }
0051     }
0052 
0053     /**
0054      * Overloading
0055      *
0056      * For PHP < 5.3.0, provides access to the getPrevious() method.
0057      *
0058      * @param  string $method
0059      * @param  array $args
0060      * @return mixed
0061      */
0062     public function __call($method, array $args)
0063     {
0064         if ('getprevious' == strtolower($method)) {
0065             return $this->_getPrevious();
0066         }
0067         return null;
0068     }
0069 
0070     /**
0071      * String representation of the exception
0072      *
0073      * @return string
0074      */
0075     public function __toString()
0076     {
0077         if (version_compare(PHP_VERSION, '5.3.0', '<')) {
0078             if (null !== ($e = $this->getPrevious())) {
0079                 return $e->__toString()
0080                        . "\n\nNext "
0081                        . parent::__toString();
0082             }
0083         }
0084         return parent::__toString();
0085     }
0086 
0087     /**
0088      * Returns previous Exception
0089      *
0090      * @return Exception|null
0091      */
0092     protected function _getPrevious()
0093     {
0094         return $this->_previous;
0095     }
0096 }