Skip to content

Commit b40e303

Browse files
author
Anton Shevchuk
committed
Fixed #473
Migrate from `cache/cache` to `symfony/cache`
1 parent 153ccc2 commit b40e303

5 files changed

Lines changed: 31 additions & 35 deletions

File tree

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
"ext-json": "*",
1010
"ext-ctype": "*",
1111
"bluzphp/collection": "~1.0",
12-
"cache/cache": "~1.0",
1312
"psr/log": "~1.1",
1413
"laminas/laminas-diactoros": "~2.6",
15-
"laminas/laminas-httphandlerrunner": "~1.4"
14+
"laminas/laminas-httphandlerrunner": "~1.4",
15+
"symfony/cache": "^5.3"
1616
},
1717
"require-dev": {
1818
"codeception/codeception": "~4.1",
@@ -27,7 +27,7 @@
2727
"ext-redis": "required by Redis adapter for Bluz\\Cache (https://github.com/bluzphp/framework/wiki/Cache)",
2828
"ext-memcached": "required by Memcached adapter for Bluz\\Cache (https://github.com/bluzphp/framework/wiki/Cache)",
2929
"phpmailer/phpmailer": "required by Bluz\\Mailer (https://github.com/bluzphp/framework/wiki/Mailer)",
30-
"predis/predis": "required by Cache\\Adapter\\Predis (https://github.com/bluzphp/framework/wiki/Cache)"
30+
"predis/predis": "required by Redis adapter for Bluz\\Cache (https://github.com/bluzphp/framework/wiki/Cache)"
3131
},
3232
"autoload": {
3333
"psr-4": {

src/Application/Application.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ public function getEnvironment(): string
8989
* Get path to Application
9090
*
9191
* @return string
92-
* @throws ReflectionException
9392
*/
9493
public function getPath(): string
9594
{
@@ -180,7 +179,6 @@ public function init(string $environment = 'production'): void
180179
*
181180
* @return void
182181
* @throws ConfigException
183-
* @throws ReflectionException
184182
*/
185183
protected function initConfig(): void
186184
{

src/Proxy/Cache.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
namespace Bluz\Proxy;
1313

1414
use Bluz\Common\Exception\ComponentException;
15-
use Cache\Hierarchy\HierarchicalPoolInterface;
16-
use Cache\TagInterop\TaggableCacheItemPoolInterface as Instance;
15+
use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface;
16+
use Symfony\Component\Cache\Adapter\AdapterInterface as Instance;
1717
use Psr\Cache\InvalidArgumentException;
1818

1919
/**
@@ -175,12 +175,10 @@ public static function prepare(string $key): string
175175
*
176176
* @return bool
177177
* @throws InvalidArgumentException
178-
* @see TaggableCacheItemPoolInterface::invalidateTag()
179-
*
180178
*/
181179
public static function clearTag(string $tag): bool
182180
{
183-
if (self::getInstance() instanceof HierarchicalPoolInterface) {
181+
if (self::getInstance() instanceof TagAwareAdapterInterface) {
184182
return self::getInstance()->invalidateTag($tag);
185183
}
186184
return false;
@@ -193,12 +191,10 @@ public static function clearTag(string $tag): bool
193191
*
194192
* @return bool
195193
* @throws InvalidArgumentException
196-
* @see TaggableCacheItemPoolInterface::invalidateTags()
197-
*
198194
*/
199195
public static function clearTags(array $tags): bool
200196
{
201-
if (self::getInstance() instanceof HierarchicalPoolInterface) {
197+
if (self::getInstance() instanceof TagAwareAdapterInterface) {
202198
return self::getInstance()->invalidateTags($tags);
203199
}
204200
return false;

src/Session/Session.php

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,15 @@ class Session
3636
*/
3737
protected $namespace = 'bluz';
3838

39+
/**
40+
* @var string Session handler name
41+
*/
42+
protected $adapter = 'files';
43+
3944
/**
4045
* @var SessionHandlerInterface Session save handler
4146
*/
42-
protected $adapter;
47+
protected $sessionHandler;
4348

4449
/**
4550
* Attempt to set the session name
@@ -197,7 +202,7 @@ public function start(): bool
197202
return true;
198203
}
199204

200-
if ($this->initAdapter()) {
205+
if ($this->init()) {
201206
return session_start();
202207
}
203208

@@ -225,23 +230,23 @@ public function destroy(): void
225230
}
226231

227232
/**
228-
* Set session save handler object
233+
* Set session handler name
229234
*
230-
* @param SessionHandlerInterface|string $saveHandler
235+
* @param string $adapter
231236
*
232237
* @return void
233238
*/
234-
public function setAdapter($saveHandler): void
239+
public function setAdapter(string $adapter): void
235240
{
236-
$this->adapter = $saveHandler;
241+
$this->adapter = $adapter;
237242
}
238243

239244
/**
240-
* Get SaveHandler Object
245+
* Get session handler name
241246
*
242-
* @return SessionHandlerInterface
247+
* @return string
243248
*/
244-
public function getAdapter(): SessionHandlerInterface
249+
public function getAdapter(): string
245250
{
246251
return $this->adapter;
247252
}
@@ -255,16 +260,16 @@ public function getAdapter(): SessionHandlerInterface
255260
* @return bool
256261
* @throws ComponentException
257262
*/
258-
protected function initAdapter(): bool
263+
protected function init(): bool
259264
{
260-
if (null === $this->adapter || 'files' === $this->adapter) {
265+
if ('files' === $this->adapter) {
261266
// try to apply settings
262267
if ($settings = $this->getOption('settings', 'files')) {
263268
$this->setSavePath($settings['save_path']);
264269
}
265270
return true;
266271
}
267-
if (is_string($this->adapter)) {
272+
if (null === $this->sessionHandler) {
268273
$adapterClass = '\\Bluz\\Session\\Adapter\\' . ucfirst($this->adapter);
269274
if (!class_exists($adapterClass) || !is_subclass_of($adapterClass, SessionHandlerInterface::class)) {
270275
throw new ComponentException("Class for session adapter `{$this->adapter}` not found");

tests/configs/default/cache.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,25 @@
1212
'adapter' => 'memcached',
1313
'pools' => [
1414
/**
15-
* @link https://github.com/php-cache/apc-adapter
15+
* @link https://symfony.com/doc/current/components/cache/adapters/apcu_adapter.html
1616
*/
17-
'apc' => function () {
18-
return new \Cache\Adapter\Apc\ApcCachePool();
17+
'apcu' => function () {
18+
return new Symfony\Component\Cache\Adapter\ApcuAdapter('bluz');
1919
},
2020
/**
21-
* @link https://github.com/php-cache/filesystem-adapter
21+
* @link https://symfony.com/doc/current/components/cache/adapters/filesystem_adapter.html
2222
*/
2323
'filesystem' => function () {
24-
$filesystemAdapter = new \League\Flysystem\Adapter\Local(PATH_DATA . '/cache');
25-
$filesystem = new \League\Flysystem\Filesystem($filesystemAdapter);
26-
27-
return new \Cache\Adapter\Filesystem\FilesystemCachePool($filesystem);
24+
return new Symfony\Component\Cache\Adapter\FilesystemTagAwareAdapter('bluz', 0, PATH_DATA . '/cache');
2825
},
2926
/**
30-
* @link https://github.com/php-cache/predis-adapter
27+
* @link https://symfony.com/doc/current/components/cache/adapters/redis_adapter.html
3128
* @link https://github.com/nrk/predis/wiki/Connection-Parameters
3229
* @link https://github.com/nrk/predis/wiki/Client-Options
3330
*/
3431
'predis' => function () {
3532
$client = new \Predis\Client('tcp:/127.0.0.1:6379');
36-
return new \Cache\Adapter\Predis\PredisCachePool($client);
33+
return new Symfony\Component\Cache\Adapter\RedisTagAwareAdapter($client, 'bluz');
3734
}
3835
]
3936
];

0 commit comments

Comments
 (0)