[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/s9e/text-formatter/src/Utils/Http/Clients/ -> Native.php (source)

   1  <?php
   2  
   3  /*
   4  * @package   s9e\TextFormatter
   5  * @copyright Copyright (c) 2010-2019 The s9e Authors
   6  * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
   7  */
   8  namespace s9e\TextFormatter\Utils\Http\Clients;
   9  use s9e\TextFormatter\Utils\Http\Client;
  10  class Native extends Client
  11  {
  12      public $gzipEnabled;
  13  	public function __construct()
  14      {
  15          $this->gzipEnabled = \extension_loaded('zlib');
  16      }
  17  	public function get($url, $headers = [])
  18      {
  19          return $this->request('GET', $url, $headers);
  20      }
  21  	public function post($url, $headers = [], $body = '')
  22      {
  23          return $this->request('POST', $url, $headers, $body);
  24      }
  25  	protected function createContext($method, array $headers, $body)
  26      {
  27          $contextOptions = [
  28              'ssl'  => ['verify_peer' => $this->sslVerifyPeer],
  29              'http' => [
  30                  'method'  => $method,
  31                  'timeout' => $this->timeout,
  32                  'header'  => $this->generateHeaders($headers, $body),
  33                  'content' => $body
  34              ]
  35          ];
  36          return \stream_context_create($contextOptions);
  37      }
  38  	protected function decompress($content)
  39      {
  40          if ($this->gzipEnabled && \substr($content, 0, 2) === "\x1f\x8b")
  41              return \gzdecode($content);
  42          return $content;
  43      }
  44  	protected function generateHeaders(array $headers, $body)
  45      {
  46          if ($this->gzipEnabled)
  47              $headers[] = 'Accept-Encoding: gzip';
  48          $headers[] = 'Content-Length: ' . \strlen($body);
  49          return $headers;
  50      }
  51  	protected function request($method, $url, $headers, $body = '')
  52      {
  53          $response = @\file_get_contents($url, \false, $this->createContext($method, $headers, $body));
  54          return (\is_string($response)) ? $this->decompress($response) : $response;
  55      }
  56  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1