| @@ 10-61 (lines=52) @@ | ||
| 7 | use League\Flysystem\Filesystem; |
|
| 8 | use League\Flysystem\FileNotFoundException; |
|
| 9 | ||
| 10 | class Flysystem2Storage implements CacheStorageInterface |
|
| 11 | { |
|
| 12 | ||
| 13 | /** |
|
| 14 | * @var Filesystem |
|
| 15 | */ |
|
| 16 | protected $filesystem; |
|
| 17 | ||
| 18 | public function __construct(LocalFilesystemAdapter $adapter) |
|
| 19 | { |
|
| 20 | $this->filesystem = new Filesystem($adapter); |
|
| 21 | } |
|
| 22 | ||
| 23 | /** |
|
| 24 | * @inheritdoc |
|
| 25 | */ |
|
| 26 | public function fetch($key) |
|
| 27 | { |
|
| 28 | if ($this->filesystem->fileExists($key)) { |
|
| 29 | // The file exist, read it! |
|
| 30 | $data = @unserialize( |
|
| 31 | $this->filesystem->read($key) |
|
| 32 | ); |
|
| 33 | ||
| 34 | if ($data instanceof CacheEntry) { |
|
| 35 | return $data; |
|
| 36 | } |
|
| 37 | } |
|
| 38 | ||
| 39 | return; |
|
| 40 | } |
|
| 41 | ||
| 42 | /** |
|
| 43 | * @inheritdoc |
|
| 44 | */ |
|
| 45 | public function save($key, CacheEntry $data) |
|
| 46 | { |
|
| 47 | return $this->filesystem->write($key, serialize($data)); |
|
| 48 | } |
|
| 49 | ||
| 50 | /** |
|
| 51 | * {@inheritdoc} |
|
| 52 | */ |
|
| 53 | public function delete($key) |
|
| 54 | { |
|
| 55 | try { |
|
| 56 | return $this->filesystem->delete($key); |
|
| 57 | } catch (FileNotFoundException $ex) { |
|
| 58 | return true; |
|
| 59 | } |
|
| 60 | } |
|
| 61 | } |
|
| 62 | ||
| @@ 10-61 (lines=52) @@ | ||
| 7 | use League\Flysystem\Filesystem; |
|
| 8 | use League\Flysystem\FileNotFoundException; |
|
| 9 | ||
| 10 | class FlysystemStorage implements CacheStorageInterface |
|
| 11 | { |
|
| 12 | ||
| 13 | /** |
|
| 14 | * @var Filesystem |
|
| 15 | */ |
|
| 16 | protected $filesystem; |
|
| 17 | ||
| 18 | public function __construct(AdapterInterface $adapter) |
|
| 19 | { |
|
| 20 | $this->filesystem = new Filesystem($adapter); |
|
| 21 | } |
|
| 22 | ||
| 23 | /** |
|
| 24 | * @inheritdoc |
|
| 25 | */ |
|
| 26 | public function fetch($key) |
|
| 27 | { |
|
| 28 | if ($this->filesystem->has($key)) { |
|
| 29 | // The file exist, read it! |
|
| 30 | $data = @unserialize( |
|
| 31 | $this->filesystem->read($key) |
|
| 32 | ); |
|
| 33 | ||
| 34 | if ($data instanceof CacheEntry) { |
|
| 35 | return $data; |
|
| 36 | } |
|
| 37 | } |
|
| 38 | ||
| 39 | return; |
|
| 40 | } |
|
| 41 | ||
| 42 | /** |
|
| 43 | * @inheritdoc |
|
| 44 | */ |
|
| 45 | public function save($key, CacheEntry $data) |
|
| 46 | { |
|
| 47 | return $this->filesystem->put($key, serialize($data)); |
|
| 48 | } |
|
| 49 | ||
| 50 | /** |
|
| 51 | * {@inheritdoc} |
|
| 52 | */ |
|
| 53 | public function delete($key) |
|
| 54 | { |
|
| 55 | try { |
|
| 56 | return $this->filesystem->delete($key); |
|
| 57 | } catch (FileNotFoundException $ex) { |
|
| 58 | return true; |
|
| 59 | } |
|
| 60 | } |
|
| 61 | } |
|
| 62 | ||