~ubuntu-branches/ubuntu/utopic/zendframework/utopic

« back to all changes in this revision

Viewing changes to library/Zend/Exception.php

  • Committer: Bazaar Package Importer
  • Author(s): Frank Habermann
  • Date: 2010-04-28 20:10:00 UTC
  • mfrom: (1.3.1 upstream) (9.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20100428201000-o347bj5qb5i3tpot
Tags: 1.10.4-1
new upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
19
19
 */
20
20
 
21
 
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
22
 
    /**
23
 
     * @category   Zend
24
 
     * @package    Zend
25
 
     * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
26
 
     * @license    http://framework.zend.com/license/new-bsd     New BSD License
27
 
     */
28
 
    class Zend_Exception extends Exception
 
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
    /**
 
35
     * Construct the exception
 
36
     *
 
37
     * @param  string $msg
 
38
     * @param  int $code
 
39
     * @param  Exception $previous
 
40
     * @return void
 
41
     */
 
42
    public function __construct($msg = '', $code = 0, Exception $previous = null)
29
43
    {
30
 
        /**
31
 
         * @var null|Exception
32
 
         */
33
 
        private $_previous = null;
34
 
 
35
 
        /**
36
 
         * Construct the exception
37
 
         *
38
 
         * @param  string $msg
39
 
         * @param  int $code
40
 
         * @param  Exception $previous
41
 
         * @return void
42
 
         */
43
 
        public function __construct($msg = '', $code = 0, Exception $previous = null)
44
 
        {
 
44
        if (version_compare(PHP_VERSION, '5.3.0', '<')) {
45
45
            parent::__construct($msg, (int) $code);
46
46
            $this->_previous = $previous;
47
 
        }
48
 
 
49
 
        /**
50
 
         * Returns previous Exception
51
 
         *
52
 
         * @return Exception|null
53
 
         */
54
 
        final public function getPrevious()
55
 
        {
56
 
            return $this->_previous;
57
 
        }
58
 
 
59
 
        /**
60
 
         * String representation of the exception
61
 
         *
62
 
         * @return string
63
 
         */
64
 
        public function __toString()
65
 
        {
 
47
        } else {
 
48
            parent::__construct($msg, (int) $code, $previous);
 
49
        }
 
50
    }
 
51
 
 
52
    /**
 
53
     * Overloading
 
54
     *
 
55
     * For PHP < 5.3.0, provides access to the getPrevious() method.
 
56
     * 
 
57
     * @param  string $method 
 
58
     * @param  array $args 
 
59
     * @return mixed
 
60
     */
 
61
    public function __call($method, array $args)
 
62
    {
 
63
        if ('getprevious' == strtolower($method)) {
 
64
            return $this->_getPrevious();
 
65
        }
 
66
        return null;
 
67
    }
 
68
 
 
69
    /**
 
70
     * String representation of the exception
 
71
     *
 
72
     * @return string
 
73
     */
 
74
    public function __toString()
 
75
    {
 
76
        if (version_compare(PHP_VERSION, '5.3.0', '<')) {
66
77
            if (null !== ($e = $this->getPrevious())) {
67
78
                return $e->__toString() 
68
 
                    . "\n\nNext " 
69
 
                    . parent::__toString();
 
79
                       . "\n\nNext " 
 
80
                       . parent::__toString();
70
81
            }
71
 
            return parent::__toString();
72
82
        }
 
83
        return parent::__toString();
73
84
    }
74
 
} else {
 
85
 
75
86
    /**
76
 
     * @category   Zend
77
 
     * @package    Zend
78
 
     * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
79
 
     * @license    http://framework.zend.com/license/new-bsd     New BSD License
 
87
     * Returns previous Exception
 
88
     *
 
89
     * @return Exception|null
80
90
     */
81
 
    class Zend_Exception extends Exception
 
91
    protected function _getPrevious()
82
92
    {
83
 
        public function __construct($msg = '', $code = 0, Exception $previous = null)
84
 
        {
85
 
            if (!is_int($code)) {
86
 
                $code = (int) $code;
87
 
            }
88
 
            parent::__construct($msg, $code, $previous);
89
 
        }
 
93
        return $this->_previous;
90
94
    }
91
95
}