Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

RequestException.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 5.02 KiB


001  <?php
002  namespace GuzzleHttp\Exception;
003   
004  use GuzzleHttp\Promise\PromiseInterface;
005  use Psr\Http\Message\RequestInterface;
006  use Psr\Http\Message\ResponseInterface;
007  use Psr\Http\Message\UriInterface;
008   
009  /**
010   * HTTP Request exception
011   */
012  class RequestException extends TransferException
013  {
014      /** @var RequestInterface */
015      private $request;
016   
017      /** @var ResponseInterface|null */
018      private $response;
019   
020      /** @var array */
021      private $handlerContext;
022   
023      public function __construct(
024          $message,
025          RequestInterface $request,
026          ResponseInterface $response = null,
027          \Exception $previous = null,
028          array $handlerContext = []
029      ) {
030          // Set the code of the exception if the response is set and not future.
031          $code = $response && !($response instanceof PromiseInterface)
032              ? $response->getStatusCode()
033              : 0;
034          parent::__construct($message, $code, $previous);
035          $this->request = $request;
036          $this->response = $response;
037          $this->handlerContext = $handlerContext;
038      }
039   
040      /**
041       * Wrap non-RequestExceptions with a RequestException
042       *
043       * @param RequestInterface $request
044       * @param \Exception       $e
045       *
046       * @return RequestException
047       */
048      public static function wrapException(RequestInterface $request, \Exception $e)
049      {
050          return $e instanceof RequestException
051              ? $e
052              : new RequestException($e->getMessage(), $request, null, $e);
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       * @param array             $ctx      Optional handler context.
062       *
063       * @return self
064       */
065      public static function create(
066          RequestInterface $request,
067          ResponseInterface $response = null,
068          \Exception $previous = null,
069          array $ctx = []
070      ) {
071          if (!$response) {
072              return new self(
073                  'Error completing request',
074                  $request,
075                  null,
076                  $previous,
077                  $ctx
078              );
079          }
080   
081          $level = (int) floor($response->getStatusCode() / 100);
082          if ($level === 4) {
083              $label = 'Client error';
084              $className = ClientException::class;
085          } elseif ($level === 5) {
086              $label = 'Server error';
087              $className = ServerException::class;
088          } else {
089              $label = 'Unsuccessful request';
090              $className = __CLASS__;
091          }
092   
093          $uri = $request->getUri();
094          $uri = static::obfuscateUri($uri);
095   
096          // Client Error: `GET /` resulted in a `404 Not Found` response:
097          // <html> ... (truncated)
098          $message = sprintf(
099              '%s: `%s %s` resulted in a `%s %s` response',
100              $label,
101              $request->getMethod(),
102              $uri,
103              $response->getStatusCode(),
104              $response->getReasonPhrase()
105          );
106   
107          $summary = static::getResponseBodySummary($response);
108   
109          if ($summary !== null) {
110              $message .= ":\n{$summary}\n";
111          }
112   
113          return new $className($message, $request, $response, $previous, $ctx);
114      }
115   
116      /**
117       * Get a short summary of the response
118       *
119       * Will return `null` if the response is not printable.
120       *
121       * @param ResponseInterface $response
122       *
123       * @return string|null
124       */
125      public static function getResponseBodySummary(ResponseInterface $response)
126      {
127          return \GuzzleHttp\Psr7\get_message_body_summary($response);
128      }
129   
130      /**
131       * Obfuscates URI if there is a username and a password present
132       *
133       * @param UriInterface $uri
134       *
135       * @return UriInterface
136       */
137      private static function obfuscateUri(UriInterface $uri)
138      {
139          $userInfo = $uri->getUserInfo();
140   
141          if (false !== ($pos = strpos($userInfo, ':'))) {
142              return $uri->withUserInfo(substr($userInfo, 0, $pos), '***');
143          }
144   
145          return $uri;
146      }
147   
148      /**
149       * Get the request that caused the exception
150       *
151       * @return RequestInterface
152       */
153      public function getRequest()
154      {
155          return $this->request;
156      }
157   
158      /**
159       * Get the associated response
160       *
161       * @return ResponseInterface|null
162       */
163      public function getResponse()
164      {
165          return $this->response;
166      }
167   
168      /**
169       * Check if a response was received
170       *
171       * @return bool
172       */
173      public function hasResponse()
174      {
175          return $this->response !== null;
176      }
177   
178      /**
179       * Get contextual information about the error from the underlying handler.
180       *
181       * The contents of this array will vary depending on which handler you are
182       * using. It may also be just an empty array. Relying on this data will
183       * couple you to a specific handler, but can give more debug information
184       * when needed.
185       *
186       * @return array
187       */
188      public function getHandlerContext()
189      {
190          return $this->handlerContext;
191      }
192  }
193