PluginProbe
User Access Manager / 2.2.21
User Access Manager v2.2.21
2.3.20 2.3.19 2.3.18 2.3.17 2.3.16 2.3.15 2.3.14 2.3.13 trunk 0.6 0.6.1 0.6.2 0.7 0.7 Beta 0.7.0.1 0.8 0.8.0.1 0.8.0.2 0.9 0.9.1 0.9.1.1 0.9.1.2 0.9.1.3 0.9.1.4 1.0 All 136 releases
← All changes | src/Cache/FileSystemCacheProvider.php +98 -11 2.3.152.2.21 View file →
@@ -1,5 +1,18 @@
1 1 <?php
2 +/**
3 + * FileSystemCacheProvider.php
4 + *
5 + * The FileSystemCacheProvider interface file.
6 + *
7 + * PHP versions 5
8 + *
9 + * @author Alexander Schneider <alexanderschneider85@gmail.com>
10 + * @copyright 2008-2017 Alexander Schneider
11 + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2
12 + * @version SVN: $id$
13 + * @link http://wordpress.org/extend/plugins/user-access-manager/
14 + */
2 15
3 16 declare(strict_types=1);
4 17
5 18 namespace UserAccessManager\Cache;
@@ -11,8 +24,13 @@
11 24 use UserAccessManager\Util\Util;
12 25 use UserAccessManager\Wrapper\Php;
13 26 use UserAccessManager\Wrapper\Wordpress;
14 27
28 +/**
29 + * Class FileSystemCacheProvider
30 + *
31 + * @package UserAccessManager\Cache
32 + */
15 33 class FileSystemCacheProvider implements CacheProviderInterface
16 34 {
17 35 const ID = 'FileSystemCacheProvider';
18 36 const CONFIG_KEY = 'uam_file_system_cache_provider';
@@ -22,20 +40,69 @@
22 40 const METHOD_IGBINARY = 'igbinary';
23 41 const METHOD_JSON = 'json';
24 42 const METHOD_VAR_EXPORT = 'var_export';
25 43
26 - private ?Config $config = null;
27 - private ?string $path = null;
44 + /**
45 + * @var Php
46 + */
47 + private $php;
28 48
49 + /**
50 + * @var Wordpress
51 + */
52 + private $wordpress;
53 +
54 + /**
55 + * @var Util
56 + */
57 + private $util;
58 +
59 + /**
60 + * @var ConfigFactory
61 + */
62 + private $configFactory;
63 +
64 + /**
65 + * @var ConfigParameterFactory
66 + */
67 + private $configParameterFactory;
68 +
69 + /**
70 + * @var null|Config
71 + */
72 + private $config = null;
73 +
74 + /**
75 + * @var string
76 + */
77 + private $path = null;
78 +
79 + /**
80 + * FileSystemCacheProvider constructor.
81 + * @param Php $php
82 + * @param Wordpress $wordpress
83 + * @param Util $util
84 + * @param ConfigFactory $configFactory
85 + * @param ConfigParameterFactory $configParameterFactory
86 + */
29 87 public function __construct(
30 - private Php $php,
31 - private Wordpress $wordpress,
32 - private Util $util,
33 - private ConfigFactory $configFactory,
34 - private ConfigParameterFactory $configParameterFactory
88 + Php $php,
89 + Wordpress $wordpress,
90 + Util $util,
91 + ConfigFactory $configFactory,
92 + ConfigParameterFactory $configParameterFactory
35 93 ) {
94 + $this->php = $php;
95 + $this->wordpress = $wordpress;
96 + $this->util = $util;
97 + $this->configFactory = $configFactory;
98 + $this->configParameterFactory = $configParameterFactory;
36 99 }
37 100
101 + /**
102 + * Returns the id.
103 + * @return string
104 + */
38 105 public function getId(): string
39 106 {
40 107 return self::ID;
41 108 }
@@ -40,8 +107,10 @@
40 107 return self::ID;
41 108 }
42 109
43 110 /**
111 + * Returns the cache path.
112 + * @return string
44 113 * @throws Exception
45 114 */
46 115 private function getPath(): string
47 116 {
@@ -56,11 +125,12 @@
56 125 return $this->path;
57 126 }
58 127
59 128 /**
129 + * Initialise the caching path.
60 130 * @throws Exception
61 131 */
62 - public function init(): void
132 + public function init()
63 133 {
64 134 $path = $this->getPath();
65 135
66 136 if (is_dir($path) === false) {
@@ -74,8 +144,10 @@
74 144 }
75 145 }
76 146
77 147 /**
148 + * Returns the cache config.
149 + * @return Config
78 150 * @throws Exception
79 151 */
80 152 public function getConfig(): Config
81 153 {
@@ -109,8 +181,10 @@
109 181 return $this->config;
110 182 }
111 183
112 184 /**
185 + * Returns the caching method.
186 + * @return string|null
113 187 * @throws Exception
114 188 */
115 189 private function getCacheMethod(): ?string
116 190 {
@@ -126,8 +200,12 @@
126 200 return $method;
127 201 }
128 202
129 203 /**
204 + * Returns the cache file name with path.
205 + * @param string|null $method
206 + * @param string $key
207 + * @return string
130 208 * @throws Exception
131 209 */
132 210 private function getCacheFile(?string $method, string $key): string
133 211 {
@@ -137,11 +215,14 @@
137 215 return $cacheFile;
138 216 }
139 217
140 218 /**
219 + * Adds a value to the cache.
220 + * @param string $key
221 + * @param mixed $value
141 222 * @throws Exception
142 223 */
143 - public function add(string $key, mixed $value): void
224 + public function add(string $key, $value)
144 225 {
145 226 $method = $this->getCacheMethod();
146 227 $cacheFile = $this->getCacheFile($method, $key);
147 228
@@ -160,11 +241,14 @@
160 241 }
161 242 }
162 243
163 244 /**
245 + * Returns a value from the cache.
246 + * @param string $key
247 + * @return mixed
164 248 * @throws Exception
165 249 */
166 - public function get(string $key): mixed
250 + public function get(string $key)
167 251 {
168 252 $method = $this->getCacheMethod();
169 253 $cacheFile = $this->getCacheFile($method, $key);
170 254
@@ -176,8 +260,9 @@
176 260 } elseif ($method === self::METHOD_JSON) {
177 261 return json_decode(file_get_contents($cacheFile), true);
178 262 } elseif ($method === self::METHOD_VAR_EXPORT) {
179 263 $cachedValue = null;
264 + /** @noinspection PhpIncludeInspection */
180 265 include($cacheFile);
181 266 return $cachedValue;
182 267 }
183 268 }
@@ -185,11 +270,13 @@
185 270 return null;
186 271 }
187 272
188 273 /**
274 + * Invalidates the cache.
275 + * @param string $key
189 276 * @throws Exception
190 277 */
191 - public function invalidate(string $key): void
278 + public function invalidate(string $key)
192 279 {
193 280 $method = $this->getCacheMethod();
194 281 $cacheFile = $this->getCacheFile($method, $key);
195 282