[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
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 Cached extends Client 11 { 12 public $client; 13 public $cacheDir; 14 public function __construct(Client $client) 15 { 16 $this->client = $client; 17 $this->timeout = $client->timeout; 18 $this->sslVerifyPeer = $client->sslVerifyPeer; 19 } 20 public function get($url, $headers = []) 21 { 22 $filepath = $this->getCachedFilepath([$url, $headers]); 23 if (isset($filepath) && \file_exists(\preg_replace('(^compress\\.zlib://)', '', $filepath))) 24 return \file_get_contents($filepath); 25 $content = $this->getClient()->get($url, $headers); 26 if (isset($filepath) && $content !== \false) 27 \file_put_contents($filepath, $content); 28 return $content; 29 } 30 public function post($url, $headers = [], $body = '') 31 { 32 return $this->getClient()->post($url, $headers, $body); 33 } 34 protected function getCachedFilepath(array $vars) 35 { 36 if (!isset($this->cacheDir)) 37 return \null; 38 $filepath = $this->cacheDir . '/http.' . $this->getCacheKey($vars); 39 if (\extension_loaded('zlib')) 40 $filepath = 'compress.zlib://' . $filepath . '.gz'; 41 return $filepath; 42 } 43 44 protected function getCacheKey(array $vars) 45 { 46 return \strtr(\base64_encode(\sha1(\serialize($vars), \true)), '/', '_'); 47 } 48 protected function getClient() 49 { 50 $this->client->timeout = $this->timeout; 51 $this->client->sslVerifyPeer = $this->sslVerifyPeer; 52 return $this->client; 53 } 54 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |