Skip to content

Commit

Permalink
(feat): Upgrade to Flysystem v2 (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
marufmax authored Nov 5, 2023
1 parent 523573c commit 65f85ca
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, dom
extensions: mbstring, dom, igbinary

- name: Validate composer.json and composer.lock
run: composer validate
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"require-dev": {
"phpunit/phpunit": "^8.5.15 || ^9.5",
"doctrine/cache": "^1.10",
"league/flysystem": "^1.0",
"league/flysystem": "^2.5",
"psr/cache": "^1.0",
"cache/array-adapter": "^0.4 || ^0.5 || ^1.0",
"illuminate/cache": "^5.0",
Expand Down
14 changes: 7 additions & 7 deletions src/Storage/FlysystemStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace Kevinrob\GuzzleCache\Storage;

use Kevinrob\GuzzleCache\CacheEntry;
use League\Flysystem\AdapterInterface;
use League\Flysystem\Filesystem;
use League\Flysystem\FileNotFoundException;
use League\Flysystem\FilesystemAdapter;
use League\Flysystem\FilesystemException;

class FlysystemStorage implements CacheStorageInterface
{
Expand All @@ -15,7 +15,7 @@ class FlysystemStorage implements CacheStorageInterface
*/
protected $filesystem;

public function __construct(AdapterInterface $adapter)
public function __construct(FilesystemAdapter $adapter)
{
$this->filesystem = new Filesystem($adapter);
}
Expand All @@ -25,7 +25,7 @@ public function __construct(AdapterInterface $adapter)
*/
public function fetch($key)
{
if ($this->filesystem->has($key)) {
if ($this->filesystem->fileExists($key)) {
// The file exist, read it!
$data = @unserialize(
$this->filesystem->read($key)
Expand All @@ -44,7 +44,7 @@ public function fetch($key)
*/
public function save($key, CacheEntry $data)
{
return $this->filesystem->put($key, serialize($data));
$this->filesystem->write($key, serialize($data));
}

/**
Expand All @@ -53,8 +53,8 @@ public function save($key, CacheEntry $data)
public function delete($key)
{
try {
return $this->filesystem->delete($key);
} catch (FileNotFoundException $ex) {
$this->filesystem->delete($key);
} catch (FilesystemException $ex) {
return true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/PrivateCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Kevinrob\GuzzleCache\Storage\Psr16CacheStorage;
use Kevinrob\GuzzleCache\Storage\VolatileRuntimeStorage;
use Kevinrob\GuzzleCache\Strategy\PrivateCacheStrategy;
use League\Flysystem\Adapter\Local;
use League\Flysystem\Local\LocalFilesystemAdapter;
use PHPUnit\Framework\TestCase;

class PrivateCacheTest extends TestCase
Expand Down Expand Up @@ -89,7 +89,7 @@ public function cacheProvider()
'doctrine.chaincache' => [ new DoctrineCacheStorage(new ChainCache([new ArrayCache()])) ],
'doctrine.filesystem' => [ new DoctrineCacheStorage(new FilesystemCache($TMP_DIR)), $TMP_DIR ],
'doctrine.phpfile' => [ new DoctrineCacheStorage(new PhpFileCache($TMP_DIR)), $TMP_DIR ],
'flysystem' => [ new FlysystemStorage(new Local($TMP_DIR)), $TMP_DIR ],
'flysystem' => [ new FlysystemStorage(new LocalFilesystemAdapter($TMP_DIR)), $TMP_DIR ],
'psr6' => [ new Psr6CacheStorage(new ArrayCachePool()) ],
'psr16' => [ new Psr16CacheStorage(new SimpleCacheBridge(new ArrayCachePool())) ],
'compressedDoctrineStorage' => [ new CompressedDoctrineCacheStorage(new ArrayCache()) ],
Expand Down
4 changes: 2 additions & 2 deletions tests/PublicCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use Kevinrob\GuzzleCache\Storage\Psr16CacheStorage;
use Kevinrob\GuzzleCache\Storage\VolatileRuntimeStorage;
use Kevinrob\GuzzleCache\Strategy\PublicCacheStrategy;
use League\Flysystem\Adapter\Local;
use League\Flysystem\Local\LocalFilesystemAdapter;
use Psr\Http\Message\RequestInterface;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -100,7 +100,7 @@ public function testCacheProvider()
new DoctrineCacheStorage(new ChainCache([new ArrayCache()])),
new DoctrineCacheStorage(new FilesystemCache($TMP_DIR)),
new DoctrineCacheStorage(new PhpFileCache($TMP_DIR)),
new FlysystemStorage(new Local($TMP_DIR)),
new FlysystemStorage(new LocalFilesystemAdapter($TMP_DIR)),
new Psr6CacheStorage(new ArrayCachePool()),
new Psr16CacheStorage(new SimpleCacheBridge(new ArrayCachePool())),
new CompressedDoctrineCacheStorage(new ArrayCache()),
Expand Down

0 comments on commit 65f85ca

Please sign in to comment.