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