Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * Exception classes for HTTP_Request2 package
4
 *
5
 * PHP version 5
6
 *
7
 * LICENSE:
8
 *
9
 * Copyright (c) 2008-2011, Alexey Borzov <avb@php.net>
10
 * All rights reserved.
11
 *
12
 * Redistribution and use in source and binary forms, with or without
13
 * modification, are permitted provided that the following conditions
14
 * are met:
15
 *
16
 *    * Redistributions of source code must retain the above copyright
17
 *      notice, this list of conditions and the following disclaimer.
18
 *    * Redistributions in binary form must reproduce the above copyright
19
 *      notice, this list of conditions and the following disclaimer in the
20
 *      documentation and/or other materials provided with the distribution.
21
 *    * The names of the authors may not be used to endorse or promote products
22
 *      derived from this software without specific prior written permission.
23
 *
24
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
26
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
28
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
32
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
 *
36
 * @category   HTTP
37
 * @package    HTTP_Request2
38
 * @author     Alexey Borzov <avb@php.net>
39
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
40
 * @version    SVN: $Id: Exception.php 308629 2011-02-24 17:34:24Z avb $
41
 * @link       http://pear.php.net/package/HTTP_Request2
42
 */
43
 
44
/**
45
 * Base class for exceptions in PEAR
46
 */
47
require_once 'PEAR/Exception.php';
48
 
49
/**
50
 * Base exception class for HTTP_Request2 package
51
 *
52
 * @category   HTTP
53
 * @package    HTTP_Request2
54
 * @version    Release: 2.0.0RC1
55
 * @link       http://pear.php.net/pepr/pepr-proposal-show.php?id=132
56
 */
57
class HTTP_Request2_Exception extends PEAR_Exception
58
{
59
    /** An invalid argument was passed to a method */
60
    const INVALID_ARGUMENT   = 1;
61
    /** Some required value was not available */
62
    const MISSING_VALUE      = 2;
63
    /** Request cannot be processed due to errors in PHP configuration */
64
    const MISCONFIGURATION   = 3;
65
    /** Error reading the local file */
66
    const READ_ERROR         = 4;
67
 
68
    /** Server returned a response that does not conform to HTTP protocol */
69
    const MALFORMED_RESPONSE = 10;
70
    /** Failure decoding Content-Encoding or Transfer-Encoding of response */
71
    const DECODE_ERROR       = 20;
72
    /** Operation timed out */
73
    const TIMEOUT            = 30;
74
    /** Number of redirects exceeded 'max_redirects' configuration parameter */
75
    const TOO_MANY_REDIRECTS = 40;
76
    /** Redirect to a protocol other than http(s):// */
77
    const NON_HTTP_REDIRECT  = 50;
78
 
79
   /**
80
    * Native error code
81
    * @var int
82
    */
83
    private $_nativeCode;
84
 
85
   /**
86
    * Constructor, can set package error code and native error code
87
    *
88
    * @param string exception message
89
    * @param int    package error code, one of class constants
90
    * @param int    error code from underlying PHP extension
91
    */
92
    public function __construct($message = null, $code = null, $nativeCode = null)
93
    {
94
        parent::__construct($message, $code);
95
        $this->_nativeCode = $nativeCode;
96
    }
97
 
98
   /**
99
    * Returns error code produced by underlying PHP extension
100
    *
101
    * For Socket Adapter this may contain error number returned by
102
    * stream_socket_client(), for Curl Adapter this will contain error number
103
    * returned by curl_errno()
104
    *
105
    * @return integer
106
    */
107
    public function getNativeCode()
108
    {
109
        return $this->_nativeCode;
110
    }
111
}
112
 
113
/**
114
 * Exception thrown in case of missing features
115
 *
116
 * @category   HTTP
117
 * @package    HTTP_Request2
118
 * @version    Release: 2.0.0RC1
119
 */
120
class HTTP_Request2_NotImplementedException extends HTTP_Request2_Exception {}
121
 
122
/**
123
 * Exception that represents error in the program logic
124
 *
125
 * This exception usually implies a programmer's error, like passing invalid
126
 * data to methods or trying to use PHP extensions that weren't installed or
127
 * enabled. Usually exceptions of this kind will be thrown before request even
128
 * starts.
129
 *
130
 * The exception will usually contain a package error code.
131
 *
132
 * @category   HTTP
133
 * @package    HTTP_Request2
134
 * @version    Release: 2.0.0RC1
135
 */
136
class HTTP_Request2_LogicException extends HTTP_Request2_Exception {}
137
 
138
/**
139
 * Exception thrown when connection to a web or proxy server fails
140
 *
141
 * The exception will not contain a package error code, but will contain
142
 * native error code, as returned by stream_socket_client() or curl_errno().
143
 *
144
 * @category   HTTP
145
 * @package    HTTP_Request2
146
 * @version    Release: 2.0.0RC1
147
 */
148
class HTTP_Request2_ConnectionException extends HTTP_Request2_Exception {}
149
 
150
/**
151
 * Exception thrown when sending or receiving HTTP message fails
152
 *
153
 * The exception may contain both package error code and native error code.
154
 *
155
 * @category   HTTP
156
 * @package    HTTP_Request2
157
 * @version    Release: 2.0.0RC1
158
 */
159
class HTTP_Request2_MessageException extends HTTP_Request2_Exception {}
160
?>