-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Flysystem 2 Storage #138
base: master
Are you sure you want to change the base?
Changes from all commits
684d321
dcfe44b
3b7502e
b7e0456
fdc6039
8b6eed5
987e815
ef74fb6
44900e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace Kevinrob\GuzzleCache\Storage; | ||
|
||
use Kevinrob\GuzzleCache\CacheEntry; | ||
use League\Flysystem\FilesystemAdapter; | ||
use League\Flysystem\Filesystem; | ||
use League\Flysystem\FileNotFoundException; | ||
|
||
class Flysystem2Storage implements CacheStorageInterface | ||
{ | ||
|
||
/** | ||
* @var Filesystem | ||
*/ | ||
protected $filesystem; | ||
|
||
public function __construct(FilesystemAdapter $adapter) | ||
{ | ||
$this->filesystem = new Filesystem($adapter); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function fetch($key) | ||
{ | ||
if ($this->filesystem->fileExists($key)) { | ||
// The file exist, read it! | ||
$data = @unserialize( | ||
$this->filesystem->read($key) | ||
); | ||
|
||
if ($data instanceof CacheEntry) { | ||
return $data; | ||
} | ||
} | ||
|
||
return; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function save($key, CacheEntry $data) | ||
{ | ||
return $this->filesystem->write($key, serialize($data)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function delete($key) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Almost the same as above:
|
||
{ | ||
try { | ||
return $this->filesystem->delete($key); | ||
} catch (FileNotFoundException $ex) { | ||
return true; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,11 +14,13 @@ | |
use Kevinrob\GuzzleCache\Storage\CompressedDoctrineCacheStorage; | ||
use Kevinrob\GuzzleCache\Storage\DoctrineCacheStorage; | ||
use Kevinrob\GuzzleCache\Storage\FlysystemStorage; | ||
use Kevinrob\GuzzleCache\Storage\Flysystem2Storage; | ||
use Kevinrob\GuzzleCache\Storage\Psr6CacheStorage; | ||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The tests doesn't run.
Maybe, there are something to add to composer.json in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Of course that's missing :). It seems to be not possible to add the same package twice. How to solve that in a satisfying way, since this is just a problem in the test not when using the code itself? Right now I'm using my version as VCS repository but I assume an implementation of Flysystem 2 is of interest in the future. Would it be odd to bump the middleware version number, and just include Flysystem 2 (at the end, Flysystem 1 can still be used it's just not tested anymore)? But can that be justified, because a newer (and incompatible version) of an adapter that not everybody is using, was included? Lots of questions. Thanks for your patience. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you cherry the commit (dpi@24d30ef) from https://github.com/dpi/guzzle-cache-middleware/tree/feature-flysystem2, it allows multiple flysystem versions and adds each version as a matrix. Not sure if it works as its unclear to me how to run Github actions on forks/PR's. If anyone has this info please enlighten/link me. At least tests succeed when running the require command with each version. |
||
use PHPUnit\Framework\TestCase; | ||
|
||
class PrivateCacheTest extends TestCase | ||
|
@@ -33,6 +35,7 @@ public function testCacheProvider() | |
new DoctrineCacheStorage(new FilesystemCache($TMP_DIR)), | ||
new DoctrineCacheStorage(new PhpFileCache($TMP_DIR)), | ||
new FlysystemStorage(new Local($TMP_DIR)), | ||
new Flysystem2Storage(new LocalFilesystemAdapter($TMP_DIR)), | ||
new Psr6CacheStorage(new ArrayCachePool()), | ||
new Psr16CacheStorage(new SimpleCacheBridge(new ArrayCachePool())), | ||
new CompressedDoctrineCacheStorage(new ArrayCache()), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs to return
NULL
not void, per\Kevinrob\GuzzleCache\Storage\CacheStorageInterface::fetch