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

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

CurlClient.php

Zuletzt modifiziert: 09.10.2024, 12:59 - Dateigröße: 3.43 KiB


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