[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/s9e/text-formatter/src/Utils/Http/Clients/ -> Curl.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 Curl extends Client
  11  {
  12      protected static $handle;
  13  	public function get($url, $headers = [])
  14      {
  15          $handle = $this->getHandle();
  16          \curl_setopt($handle, \CURLOPT_HTTPGET,    \true);
  17          \curl_setopt($handle, \CURLOPT_HTTPHEADER, $headers);
  18          \curl_setopt($handle, \CURLOPT_URL,        $url);
  19          return \curl_exec($handle);
  20      }
  21  	public function post($url, $headers = [], $body = '')
  22      {
  23          $headers[] = 'Content-Length: ' . \strlen($body);
  24          $handle = $this->getHandle();
  25          \curl_setopt($handle, \CURLOPT_HTTPHEADER, $headers);
  26          \curl_setopt($handle, \CURLOPT_POST,       \true);
  27          \curl_setopt($handle, \CURLOPT_POSTFIELDS, $body);
  28          \curl_setopt($handle, \CURLOPT_URL,        $url);
  29          return \curl_exec($handle);
  30      }
  31  	protected function getHandle()
  32      {
  33          if (!isset(self::$handle))
  34              self::$handle = $this->getNewHandle();
  35          \curl_setopt(self::$handle, \CURLOPT_SSL_VERIFYPEER, $this->sslVerifyPeer);
  36          \curl_setopt(self::$handle, \CURLOPT_TIMEOUT,        $this->timeout);
  37          return self::$handle;
  38      }
  39  	protected function getNewHandle()
  40      {
  41          $handle = \curl_init();
  42          \curl_setopt($handle, \CURLOPT_ENCODING,       '');
  43          \curl_setopt($handle, \CURLOPT_FAILONERROR,    \true);
  44          \curl_setopt($handle, \CURLOPT_FOLLOWLOCATION, \true);
  45          \curl_setopt($handle, \CURLOPT_RETURNTRANSFER, \true);
  46          return $handle;
  47      }
  48  }


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