1 | <?php
|
---|
2 | /**
|
---|
3 | * Exception classes for HTTP_Request2 package
|
---|
4 | *
|
---|
5 | * PHP version 5
|
---|
6 | *
|
---|
7 | * LICENSE:
|
---|
8 | *
|
---|
9 | * Copyright (c) 2008-2012, 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 324415 2012-03-21 10:50:50Z 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 | * @author Alexey Borzov <avb@php.net>
|
---|
55 | * @license http://opensource.org/licenses/bsd-license.php New BSD License
|
---|
56 | * @version Release: 2.1.1
|
---|
57 | * @link http://pear.php.net/package/HTTP_Request2
|
---|
58 | * @link http://pear.php.net/pepr/pepr-proposal-show.php?id=132
|
---|
59 | */
|
---|
60 | class HTTP_Request2_Exception extends PEAR_Exception
|
---|
61 | {
|
---|
62 | /** An invalid argument was passed to a method */
|
---|
63 | const INVALID_ARGUMENT = 1;
|
---|
64 | /** Some required value was not available */
|
---|
65 | const MISSING_VALUE = 2;
|
---|
66 | /** Request cannot be processed due to errors in PHP configuration */
|
---|
67 | const MISCONFIGURATION = 3;
|
---|
68 | /** Error reading the local file */
|
---|
69 | const READ_ERROR = 4;
|
---|
70 |
|
---|
71 | /** Server returned a response that does not conform to HTTP protocol */
|
---|
72 | const MALFORMED_RESPONSE = 10;
|
---|
73 | /** Failure decoding Content-Encoding or Transfer-Encoding of response */
|
---|
74 | const DECODE_ERROR = 20;
|
---|
75 | /** Operation timed out */
|
---|
76 | const TIMEOUT = 30;
|
---|
77 | /** Number of redirects exceeded 'max_redirects' configuration parameter */
|
---|
78 | const TOO_MANY_REDIRECTS = 40;
|
---|
79 | /** Redirect to a protocol other than http(s):// */
|
---|
80 | const NON_HTTP_REDIRECT = 50;
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * Native error code
|
---|
84 | * @var int
|
---|
85 | */
|
---|
86 | private $_nativeCode;
|
---|
87 |
|
---|
88 | /**
|
---|
89 | * Constructor, can set package error code and native error code
|
---|
90 | *
|
---|
91 | * @param string $message exception message
|
---|
92 | * @param int $code package error code, one of class constants
|
---|
93 | * @param int $nativeCode error code from underlying PHP extension
|
---|
94 | */
|
---|
95 | public function __construct($message = null, $code = null, $nativeCode = null)
|
---|
96 | {
|
---|
97 | parent::__construct($message, $code);
|
---|
98 | $this->_nativeCode = $nativeCode;
|
---|
99 | }
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * Returns error code produced by underlying PHP extension
|
---|
103 | *
|
---|
104 | * For Socket Adapter this may contain error number returned by
|
---|
105 | * stream_socket_client(), for Curl Adapter this will contain error number
|
---|
106 | * returned by curl_errno()
|
---|
107 | *
|
---|
108 | * @return integer
|
---|
109 | */
|
---|
110 | public function getNativeCode()
|
---|
111 | {
|
---|
112 | return $this->_nativeCode;
|
---|
113 | }
|
---|
114 | }
|
---|
115 |
|
---|
116 | /**
|
---|
117 | * Exception thrown in case of missing features
|
---|
118 | *
|
---|
119 | * @category HTTP
|
---|
120 | * @package HTTP_Request2
|
---|
121 | * @author Alexey Borzov <avb@php.net>
|
---|
122 | * @license http://opensource.org/licenses/bsd-license.php New BSD License
|
---|
123 | * @version Release: 2.1.1
|
---|
124 | * @link http://pear.php.net/package/HTTP_Request2
|
---|
125 | */
|
---|
126 | class HTTP_Request2_NotImplementedException extends HTTP_Request2_Exception
|
---|
127 | {
|
---|
128 | }
|
---|
129 |
|
---|
130 | /**
|
---|
131 | * Exception that represents error in the program logic
|
---|
132 | *
|
---|
133 | * This exception usually implies a programmer's error, like passing invalid
|
---|
134 | * data to methods or trying to use PHP extensions that weren't installed or
|
---|
135 | * enabled. Usually exceptions of this kind will be thrown before request even
|
---|
136 | * starts.
|
---|
137 | *
|
---|
138 | * The exception will usually contain a package error code.
|
---|
139 | *
|
---|
140 | * @category HTTP
|
---|
141 | * @package HTTP_Request2
|
---|
142 | * @author Alexey Borzov <avb@php.net>
|
---|
143 | * @license http://opensource.org/licenses/bsd-license.php New BSD License
|
---|
144 | * @version Release: 2.1.1
|
---|
145 | * @link http://pear.php.net/package/HTTP_Request2
|
---|
146 | */
|
---|
147 | class HTTP_Request2_LogicException extends HTTP_Request2_Exception
|
---|
148 | {
|
---|
149 | }
|
---|
150 |
|
---|
151 | /**
|
---|
152 | * Exception thrown when connection to a web or proxy server fails
|
---|
153 | *
|
---|
154 | * The exception will not contain a package error code, but will contain
|
---|
155 | * native error code, as returned by stream_socket_client() or curl_errno().
|
---|
156 | *
|
---|
157 | * @category HTTP
|
---|
158 | * @package HTTP_Request2
|
---|
159 | * @author Alexey Borzov <avb@php.net>
|
---|
160 | * @license http://opensource.org/licenses/bsd-license.php New BSD License
|
---|
161 | * @version Release: 2.1.1
|
---|
162 | * @link http://pear.php.net/package/HTTP_Request2
|
---|
163 | */
|
---|
164 | class HTTP_Request2_ConnectionException extends HTTP_Request2_Exception
|
---|
165 | {
|
---|
166 | }
|
---|
167 |
|
---|
168 | /**
|
---|
169 | * Exception thrown when sending or receiving HTTP message fails
|
---|
170 | *
|
---|
171 | * The exception may contain both package error code and native error code.
|
---|
172 | *
|
---|
173 | * @category HTTP
|
---|
174 | * @package HTTP_Request2
|
---|
175 | * @author Alexey Borzov <avb@php.net>
|
---|
176 | * @license http://opensource.org/licenses/bsd-license.php New BSD License
|
---|
177 | * @version Release: 2.1.1
|
---|
178 | * @link http://pear.php.net/package/HTTP_Request2
|
---|
179 | */
|
---|
180 | class HTTP_Request2_MessageException extends HTTP_Request2_Exception
|
---|
181 | {
|
---|
182 | }
|
---|
183 | ?> |
---|