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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
Cached.php
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 Cached extends Client
013 {
014 /**
015 * @var Client
016 */
017 public $client;
018
019 /**
020 * @var string
021 */
022 public $cacheDir;
023
024 /**
025 * @param Client $client
026 */
027 public function __construct(Client $client)
028 {
029 $this->client = $client;
030 $this->timeout = $client->timeout;
031 $this->sslVerifyPeer = $client->sslVerifyPeer;
032 }
033
034 /**
035 * {@inheritdoc}
036 */
037 public function get($url, array $options = [])
038 {
039 $filepath = $this->getCachedFilepath([$url, $options]);
040 if (isset($filepath) && file_exists(preg_replace('(^compress\\.zlib://)', '', $filepath)))
041 {
042 return file_get_contents($filepath);
043 }
044
045 $content = $this->getClient()->get($url, $options);
046 if (isset($filepath) && $content !== false)
047 {
048 file_put_contents($filepath, $content);
049 }
050
051 return $content;
052 }
053
054 /**
055 * {@inheritdoc}
056 */
057 public function post($url, array $options = [], $body = '')
058 {
059 return $this->getClient()->post($url, $options, $body);
060 }
061
062 /**
063 * Generate and return a filepath that matches given vars
064 *
065 * @param array $vars
066 * @return string
067 */
068 protected function getCachedFilepath(array $vars)
069 {
070 if (!isset($this->cacheDir))
071 {
072 return null;
073 }
074
075 $filepath = $this->cacheDir . '/http.' . $this->getCacheKey($vars);
076 if (extension_loaded('zlib'))
077 {
078 $filepath = 'compress.zlib://' . $filepath . '.gz';
079 }
080
081 return $filepath;
082 }
083
084
085 /**
086 * Generate a key for a given set of values
087 *
088 * @param string[] $vars
089 * @return string
090 */
091 protected function getCacheKey(array $vars)
092 {
093 return strtr(base64_encode(sha1(serialize($vars), true)), '/', '_');
094 }
095
096 /**
097 * Return cached client configured with this client's options
098 *
099 * @return Client
100 */
101 protected function getClient()
102 {
103 $this->client->timeout = $this->timeout;
104 $this->client->sslVerifyPeer = $this->sslVerifyPeer;
105
106 return $this->client;
107 }
108 }