Verzeichnisstruktur phpBB-3.1.0
- Veröffentlicht
- 27.10.2014
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 |
StreamClient.php
01 <?php
02 namespace OAuth\Common\Http\Client;
03
04 use OAuth\Common\Http\Exception\TokenResponseException;
05 use OAuth\Common\Http\Uri\UriInterface;
06
07 /**
08 * Client implementation for streams/file_get_contents
09 */
10 class StreamClient extends AbstractClient
11 {
12 /**
13 * Any implementing HTTP providers should send a request to the provided endpoint with the parameters.
14 * They should return, in string form, the response body and throw an exception on error.
15 *
16 * @param UriInterface $endpoint
17 * @param mixed $requestBody
18 * @param array $extraHeaders
19 * @param string $method
20 * @return string
21 * @throws TokenResponseException
22 * @throws \InvalidArgumentException
23 */
24 public function retrieveResponse(UriInterface $endpoint, $requestBody, array $extraHeaders = array(), $method = 'POST')
25 {
26 // Normalize method name
27 $method = strtoupper($method);
28
29 $this->normalizeHeaders($extraHeaders);
30
31 if( $method === 'GET' && !empty($requestBody) ) {
32 throw new \InvalidArgumentException('No body expected for "GET" request.');
33 }
34
35 if( !isset($extraHeaders['Content-type'] ) && $method === 'POST' && is_array($requestBody) ) {
36 $extraHeaders['Content-type'] = 'Content-type: application/x-www-form-urlencoded';
37 }
38
39 $extraHeaders['Host'] = 'Host: '.$endpoint->getHost();
40 $extraHeaders['Connection'] = 'Connection: close';
41
42 if( is_array($requestBody) ) {
43 $requestBody = http_build_query($requestBody, null, '&');
44 }
45
46 $context = $this->generateStreamContext($requestBody, $extraHeaders, $method);
47
48 $level = error_reporting(0);
49 $response = file_get_contents($endpoint->getAbsoluteUri(), false, $context);
50 error_reporting($level);
51 if( false === $response ) {
52 $lastError = error_get_last();
53 if (is_null($lastError))
54 throw new TokenResponseException( 'Failed to request resource.' );
55 throw new TokenResponseException( $lastError['message'] );
56 }
57
58 return $response;
59 }
60
61 private function generateStreamContext($body, $headers, $method)
62 {
63 return stream_context_create(array(
64 'http' => array(
65 'method' => $method,
66 'header' => array_values($headers),
67 'content' => $body,
68 'protocol_version' => '1.1',
69 'user_agent' => 'Lusitanian OAuth Client',
70 'max_redirects' => $this->maxRedirects,
71 'timeout' => $this->timeout
72 ),
73 ));
74 }
75 }
76