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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
CurlClient.php
001 <?php
002
003 namespace OAuth\Common\Http\Client;
004
005 use InvalidArgumentException;
006 use OAuth\Common\Http\Exception\TokenResponseException;
007 use OAuth\Common\Http\Uri\UriInterface;
008
009 /**
010 * Client implementation for cURL.
011 */
012 class CurlClient extends AbstractClient
013 {
014 /**
015 * If true, explicitly sets cURL to use SSL version 3. Use this if cURL
016 * compiles with GnuTLS SSL.
017 *
018 * @var bool
019 */
020 private $forceSSL3 = false;
021
022 /**
023 * Additional parameters (as `key => value` pairs) to be passed to `curl_setopt`.
024 *
025 * @var array
026 */
027 private $parameters = [];
028
029 /**
030 * Additional `curl_setopt` parameters.
031 */
032 public function setCurlParameters(array $parameters): void
033 {
034 $this->parameters = $parameters;
035 }
036
037 /**
038 * @param bool $force
039 *
040 * @return CurlClient
041 */
042 public function setForceSSL3($force)
043 {
044 $this->forceSSL3 = $force;
045
046 return $this;
047 }
048
049 /**
050 * Any implementing HTTP providers should send a request to the provided endpoint with the parameters.
051 * They should return, in string form, the response body and throw an exception on error.
052 *
053 * @param mixed $requestBody
054 * @param string $method
055 *
056 * @return string
057 */
058 public function retrieveResponse(
059 UriInterface $endpoint,
060 $requestBody,
061 array $extraHeaders = [],
062 $method = 'POST'
063 ) {
064 // Normalize method name
065 $method = strtoupper($method);
066
067 $extraHeaders = $this->normalizeHeaders($extraHeaders);
068
069 if ($method === 'GET' && !empty($requestBody)) {
070 throw new InvalidArgumentException('No body expected for "GET" request.');
071 }
072
073 if (!isset($extraHeaders['Content-Type']) && $method === 'POST' && is_array($requestBody)) {
074 $extraHeaders['Content-Type'] = 'Content-Type: application/x-www-form-urlencoded';
075 }
076
077 $extraHeaders['Host'] = 'Host: ' . $endpoint->getHost();
078 $extraHeaders['Connection'] = 'Connection: close';
079
080 $ch = curl_init();
081
082 curl_setopt($ch, CURLOPT_URL, $endpoint->getAbsoluteUri());
083
084 if ($method === 'POST' || $method === 'PUT') {
085 if ($requestBody && is_array($requestBody)) {
086 $requestBody = http_build_query($requestBody, '', '&');
087 }
088
089 if ($method === 'PUT') {
090 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
091 } else {
092 curl_setopt($ch, CURLOPT_POST, true);
093 }
094
095 curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody);
096 } else {
097 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
098 }
099
100 if ($this->maxRedirects > 0) {
101 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
102 curl_setopt($ch, CURLOPT_MAXREDIRS, $this->maxRedirects);
103 }
104
105 curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
106 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
107 curl_setopt($ch, CURLOPT_HEADER, false);
108 curl_setopt($ch, CURLOPT_HTTPHEADER, $extraHeaders);
109 curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent);
110
111 foreach ($this->parameters as $key => $value) {
112 curl_setopt($ch, $key, $value);
113 }
114
115 $response = curl_exec($ch);
116 $responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
117
118 if (false === $response) {
119 $errNo = curl_errno($ch);
120 $errStr = curl_error($ch);
121 curl_close($ch);
122 if (empty($errStr)) {
123 throw new TokenResponseException('Failed to request resource.', $responseCode);
124 }
125
126 throw new TokenResponseException('cURL Error # ' . $errNo . ': ' . $errStr, $responseCode);
127 }
128
129 curl_close($ch);
130
131 return $response;
132 }
133 }
134