Skip to content

Commit 65f85ca

Browse files
authored
(feat): Upgrade to Flysystem v2 (#183)
1 parent 523573c commit 65f85ca

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
uses: shivammathur/setup-php@v2
1919
with:
2020
php-version: ${{ matrix.php-versions }}
21-
extensions: mbstring, dom
21+
extensions: mbstring, dom, igbinary
2222

2323
- name: Validate composer.json and composer.lock
2424
run: composer validate

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"require-dev": {
2222
"phpunit/phpunit": "^8.5.15 || ^9.5",
2323
"doctrine/cache": "^1.10",
24-
"league/flysystem": "^1.0",
24+
"league/flysystem": "^2.5",
2525
"psr/cache": "^1.0",
2626
"cache/array-adapter": "^0.4 || ^0.5 || ^1.0",
2727
"illuminate/cache": "^5.0",

src/Storage/FlysystemStorage.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
namespace Kevinrob\GuzzleCache\Storage;
44

55
use Kevinrob\GuzzleCache\CacheEntry;
6-
use League\Flysystem\AdapterInterface;
76
use League\Flysystem\Filesystem;
8-
use League\Flysystem\FileNotFoundException;
7+
use League\Flysystem\FilesystemAdapter;
8+
use League\Flysystem\FilesystemException;
99

1010
class FlysystemStorage implements CacheStorageInterface
1111
{
@@ -15,7 +15,7 @@ class FlysystemStorage implements CacheStorageInterface
1515
*/
1616
protected $filesystem;
1717

18-
public function __construct(AdapterInterface $adapter)
18+
public function __construct(FilesystemAdapter $adapter)
1919
{
2020
$this->filesystem = new Filesystem($adapter);
2121
}
@@ -25,7 +25,7 @@ public function __construct(AdapterInterface $adapter)
2525
*/
2626
public function fetch($key)
2727
{
28-
if ($this->filesystem->has($key)) {
28+
if ($this->filesystem->fileExists($key)) {
2929
// The file exist, read it!
3030
$data = @unserialize(
3131
$this->filesystem->read($key)
@@ -44,7 +44,7 @@ public function fetch($key)
4444
*/
4545
public function save($key, CacheEntry $data)
4646
{
47-
return $this->filesystem->put($key, serialize($data));
47+
$this->filesystem->write($key, serialize($data));
4848
}
4949

5050
/**
@@ -53,8 +53,8 @@ public function save($key, CacheEntry $data)
5353
public function delete($key)
5454
{
5555
try {
56-
return $this->filesystem->delete($key);
57-
} catch (FileNotFoundException $ex) {
56+
$this->filesystem->delete($key);
57+
} catch (FilesystemException $ex) {
5858
return true;
5959
}
6060
}

tests/PrivateCacheTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use Kevinrob\GuzzleCache\Storage\Psr16CacheStorage;
1919
use Kevinrob\GuzzleCache\Storage\VolatileRuntimeStorage;
2020
use Kevinrob\GuzzleCache\Strategy\PrivateCacheStrategy;
21-
use League\Flysystem\Adapter\Local;
21+
use League\Flysystem\Local\LocalFilesystemAdapter;
2222
use PHPUnit\Framework\TestCase;
2323

2424
class PrivateCacheTest extends TestCase
@@ -89,7 +89,7 @@ public function cacheProvider()
8989
'doctrine.chaincache' => [ new DoctrineCacheStorage(new ChainCache([new ArrayCache()])) ],
9090
'doctrine.filesystem' => [ new DoctrineCacheStorage(new FilesystemCache($TMP_DIR)), $TMP_DIR ],
9191
'doctrine.phpfile' => [ new DoctrineCacheStorage(new PhpFileCache($TMP_DIR)), $TMP_DIR ],
92-
'flysystem' => [ new FlysystemStorage(new Local($TMP_DIR)), $TMP_DIR ],
92+
'flysystem' => [ new FlysystemStorage(new LocalFilesystemAdapter($TMP_DIR)), $TMP_DIR ],
9393
'psr6' => [ new Psr6CacheStorage(new ArrayCachePool()) ],
9494
'psr16' => [ new Psr16CacheStorage(new SimpleCacheBridge(new ArrayCachePool())) ],
9595
'compressedDoctrineStorage' => [ new CompressedDoctrineCacheStorage(new ArrayCache()) ],

tests/PublicCacheTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
use Kevinrob\GuzzleCache\Storage\Psr16CacheStorage;
2323
use Kevinrob\GuzzleCache\Storage\VolatileRuntimeStorage;
2424
use Kevinrob\GuzzleCache\Strategy\PublicCacheStrategy;
25-
use League\Flysystem\Adapter\Local;
25+
use League\Flysystem\Local\LocalFilesystemAdapter;
2626
use Psr\Http\Message\RequestInterface;
2727
use PHPUnit\Framework\TestCase;
2828

@@ -100,7 +100,7 @@ public function testCacheProvider()
100100
new DoctrineCacheStorage(new ChainCache([new ArrayCache()])),
101101
new DoctrineCacheStorage(new FilesystemCache($TMP_DIR)),
102102
new DoctrineCacheStorage(new PhpFileCache($TMP_DIR)),
103-
new FlysystemStorage(new Local($TMP_DIR)),
103+
new FlysystemStorage(new LocalFilesystemAdapter($TMP_DIR)),
104104
new Psr6CacheStorage(new ArrayCachePool()),
105105
new Psr16CacheStorage(new SimpleCacheBridge(new ArrayCachePool())),
106106
new CompressedDoctrineCacheStorage(new ArrayCache()),

0 commit comments

Comments
 (0)