Exception.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. /**
  3. * Exception classes for HTTP_Request2 package
  4. *
  5. * PHP version 5
  6. *
  7. * LICENSE
  8. *
  9. * This source file is subject to BSD 3-Clause License that is bundled
  10. * with this package in the file LICENSE and available at the URL
  11. * https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
  12. *
  13. * @category HTTP
  14. * @package HTTP_Request2
  15. * @author Alexey Borzov <avb@php.net>
  16. * @copyright 2008-2014 Alexey Borzov <avb@php.net>
  17. * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
  18. * @link http://pear.php.net/package/HTTP_Request2
  19. */
  20. /**
  21. * Base class for exceptions in PEAR
  22. */
  23. require_once 'PEAR/Exception.php';
  24. /**
  25. * Base exception class for HTTP_Request2 package
  26. *
  27. * @category HTTP
  28. * @package HTTP_Request2
  29. * @author Alexey Borzov <avb@php.net>
  30. * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
  31. * @version Release: 2.2.1
  32. * @link http://pear.php.net/package/HTTP_Request2
  33. * @link http://pear.php.net/pepr/pepr-proposal-show.php?id=132
  34. */
  35. class HTTP_Request2_Exception extends PEAR_Exception
  36. {
  37. /** An invalid argument was passed to a method */
  38. const INVALID_ARGUMENT = 1;
  39. /** Some required value was not available */
  40. const MISSING_VALUE = 2;
  41. /** Request cannot be processed due to errors in PHP configuration */
  42. const MISCONFIGURATION = 3;
  43. /** Error reading the local file */
  44. const READ_ERROR = 4;
  45. /** Server returned a response that does not conform to HTTP protocol */
  46. const MALFORMED_RESPONSE = 10;
  47. /** Failure decoding Content-Encoding or Transfer-Encoding of response */
  48. const DECODE_ERROR = 20;
  49. /** Operation timed out */
  50. const TIMEOUT = 30;
  51. /** Number of redirects exceeded 'max_redirects' configuration parameter */
  52. const TOO_MANY_REDIRECTS = 40;
  53. /** Redirect to a protocol other than http(s):// */
  54. const NON_HTTP_REDIRECT = 50;
  55. /**
  56. * Native error code
  57. * @var int
  58. */
  59. private $_nativeCode;
  60. /**
  61. * Constructor, can set package error code and native error code
  62. *
  63. * @param string $message exception message
  64. * @param int $code package error code, one of class constants
  65. * @param int $nativeCode error code from underlying PHP extension
  66. */
  67. public function __construct($message = null, $code = null, $nativeCode = null)
  68. {
  69. parent::__construct($message, $code);
  70. $this->_nativeCode = $nativeCode;
  71. }
  72. /**
  73. * Returns error code produced by underlying PHP extension
  74. *
  75. * For Socket Adapter this may contain error number returned by
  76. * stream_socket_client(), for Curl Adapter this will contain error number
  77. * returned by curl_errno()
  78. *
  79. * @return integer
  80. */
  81. public function getNativeCode()
  82. {
  83. return $this->_nativeCode;
  84. }
  85. }
  86. /**
  87. * Exception thrown in case of missing features
  88. *
  89. * @category HTTP
  90. * @package HTTP_Request2
  91. * @author Alexey Borzov <avb@php.net>
  92. * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
  93. * @version Release: 2.2.1
  94. * @link http://pear.php.net/package/HTTP_Request2
  95. */
  96. class HTTP_Request2_NotImplementedException extends HTTP_Request2_Exception
  97. {
  98. }
  99. /**
  100. * Exception that represents error in the program logic
  101. *
  102. * This exception usually implies a programmer's error, like passing invalid
  103. * data to methods or trying to use PHP extensions that weren't installed or
  104. * enabled. Usually exceptions of this kind will be thrown before request even
  105. * starts.
  106. *
  107. * The exception will usually contain a package error code.
  108. *
  109. * @category HTTP
  110. * @package HTTP_Request2
  111. * @author Alexey Borzov <avb@php.net>
  112. * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
  113. * @version Release: 2.2.1
  114. * @link http://pear.php.net/package/HTTP_Request2
  115. */
  116. class HTTP_Request2_LogicException extends HTTP_Request2_Exception
  117. {
  118. }
  119. /**
  120. * Exception thrown when connection to a web or proxy server fails
  121. *
  122. * The exception will not contain a package error code, but will contain
  123. * native error code, as returned by stream_socket_client() or curl_errno().
  124. *
  125. * @category HTTP
  126. * @package HTTP_Request2
  127. * @author Alexey Borzov <avb@php.net>
  128. * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
  129. * @version Release: 2.2.1
  130. * @link http://pear.php.net/package/HTTP_Request2
  131. */
  132. class HTTP_Request2_ConnectionException extends HTTP_Request2_Exception
  133. {
  134. }
  135. /**
  136. * Exception thrown when sending or receiving HTTP message fails
  137. *
  138. * The exception may contain both package error code and native error code.
  139. *
  140. * @category HTTP
  141. * @package HTTP_Request2
  142. * @author Alexey Borzov <avb@php.net>
  143. * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
  144. * @version Release: 2.2.1
  145. * @link http://pear.php.net/package/HTTP_Request2
  146. */
  147. class HTTP_Request2_MessageException extends HTTP_Request2_Exception
  148. {
  149. }
  150. ?>