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