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

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

Native.php

Zuletzt modifiziert: 02.04.2025, 15:04 - Dateigröße: 2.76 KiB


001  <?php
002   
003  /**
004  * @package   s9e\TextFormatter
005  * @copyright Copyright (c) 2010-2022 The s9e authors
006  * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
007  */
008  namespace s9e\TextFormatter\Utils\Http\Clients;
009   
010  use s9e\TextFormatter\Utils\Http\Client;
011   
012  class Native extends Client
013  {
014      /**
015      * @var bool Whether to use gzip encoding
016      */
017      public $gzipEnabled;
018   
019      /**
020      * Constructor
021      */
022      public function __construct()
023      {
024          $this->gzipEnabled = extension_loaded('zlib');
025      }
026   
027      /**
028      * {@inheritdoc}
029      */
030      public function get($url, array $options = [])
031      {
032          return $this->request('GET', $url, $options);
033      }
034   
035      /**
036      * {@inheritdoc}
037      */
038      public function post($url, array $options = [], $body = '')
039      {
040          return $this->request('POST', $url, $options, $body);
041      }
042   
043      /**
044      * Create a stream context for given request
045      *
046      * @param  string   $method  Request method
047      * @param  array    $options Request options
048      * @param  string   $body    Request body
049      * @return resource
050      */
051      protected function createContext($method, array $options, $body)
052      {
053          $contextOptions = [
054              'ssl'  => ['verify_peer' => $this->sslVerifyPeer],
055              'http' => [
056                  'method'  => $method,
057                  'timeout' => $this->timeout,
058                  'header'  => $this->generateHeaders($options, $body),
059                  'content' => $body
060              ]
061          ];
062   
063          return stream_context_create($contextOptions);
064      }
065   
066      /**
067      * Decompress given page if applicable
068      *
069      * @param  string $content Response body, potentially compressed
070      * @return string          Response body, uncompressed
071      */
072      protected function decompress($content)
073      {
074          if ($this->gzipEnabled && substr($content, 0, 2) === "\x1f\x8b")
075          {
076              return gzdecode($content);
077          }
078   
079          return $content;
080      }
081   
082      /**
083      * Generate a list of headers for given request
084      *
085      * @param  array    $options Request options
086      * @param  string   $body    Request body
087      * @return string[]
088      */
089      protected function generateHeaders(array $options, $body)
090      {
091          $options += ['headers' => []];
092          if ($this->gzipEnabled)
093          {
094              $options['headers'][] = 'Accept-Encoding: gzip';
095          }
096          $options['headers'][] = 'Content-Length: ' . strlen($body);
097   
098          return $options['headers'];
099      }
100   
101      /**
102      * Execute an HTTP request
103      *
104      * @param  string      $method  Request method
105      * @param  string      $url     Request URL
106      * @param  array       $options Request options
107      * @param  string      $body    Request body
108      * @return string|bool          Response body or FALSE
109      */
110      protected function request($method, $url, array $options, $body = '')
111      {
112          $response = @file_get_contents($url, false, $this->createContext($method, $options, $body));
113          if ($response === false)
114          {
115              return false;
116          }
117   
118          $response = $this->decompress($response);
119          if (!empty($options['returnHeaders']))
120          {
121              $response = implode("\r\n", $http_response_header) . "\r\n\r\n" . $response;
122          }
123   
124          return $response;
125      }
126  }