Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
RequestException.php
001 <?php
002 namespace GuzzleHttp\Exception;
003
004 use GuzzleHttp\Message\RequestInterface;
005 use GuzzleHttp\Message\ResponseInterface;
006 use GuzzleHttp\Ring\Exception\ConnectException;
007 use GuzzleHttp\Exception\ConnectException as HttpConnectException;
008 use GuzzleHttp\Ring\Future\FutureInterface;
009
010 /**
011 * HTTP Request exception
012 */
013 class RequestException extends TransferException
014 {
015 /** @var RequestInterface */
016 private $request;
017
018 /** @var ResponseInterface */
019 private $response;
020
021 public function __construct(
022 $message,
023 RequestInterface $request,
024 ResponseInterface $response = null,
025 \Exception $previous = null
026 ) {
027 // Set the code of the exception if the response is set and not future.
028 $code = $response && !($response instanceof FutureInterface)
029 ? $response->getStatusCode()
030 : 0;
031 parent::__construct($message, $code, $previous);
032 $this->request = $request;
033 $this->response = $response;
034 }
035
036 /**
037 * Wrap non-RequestExceptions with a RequestException
038 *
039 * @param RequestInterface $request
040 * @param \Exception $e
041 *
042 * @return RequestException
043 */
044 public static function wrapException(RequestInterface $request, \Exception $e)
045 {
046 if ($e instanceof RequestException) {
047 return $e;
048 } elseif ($e instanceof ConnectException) {
049 return new HttpConnectException($e->getMessage(), $request, null, $e);
050 } else {
051 return new RequestException($e->getMessage(), $request, null, $e);
052 }
053 }
054
055 /**
056 * Factory method to create a new exception with a normalized error message
057 *
058 * @param RequestInterface $request Request
059 * @param ResponseInterface $response Response received
060 * @param \Exception $previous Previous exception
061 *
062 * @return self
063 */
064 public static function create(
065 RequestInterface $request,
066 ResponseInterface $response = null,
067 \Exception $previous = null
068 ) {
069 if (!$response) {
070 return new self('Error completing request', $request, null, $previous);
071 }
072
073 $level = floor($response->getStatusCode() / 100);
074 if ($level == '4') {
075 $label = 'Client error response';
076 $className = __NAMESPACE__ . '\\ClientException';
077 } elseif ($level == '5') {
078 $label = 'Server error response';
079 $className = __NAMESPACE__ . '\\ServerException';
080 } else {
081 $label = 'Unsuccessful response';
082 $className = __CLASS__;
083 }
084
085 $message = $label . ' [url] ' . $request->getUrl()
086 . ' [status code] ' . $response->getStatusCode()
087 . ' [reason phrase] ' . $response->getReasonPhrase();
088
089 return new $className($message, $request, $response, $previous);
090 }
091
092 /**
093 * Get the request that caused the exception
094 *
095 * @return RequestInterface
096 */
097 public function getRequest()
098 {
099 return $this->request;
100 }
101
102 /**
103 * Get the associated response
104 *
105 * @return ResponseInterface|null
106 */
107 public function getResponse()
108 {
109 return $this->response;
110 }
111
112 /**
113 * Check if a response was received
114 *
115 * @return bool
116 */
117 public function hasResponse()
118 {
119 return $this->response !== null;
120 }
121 }
122