diff --git a/composer.json b/composer.json index 2f241b0..37fe751 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ "composer/semver": "^3.2", "czproject/git-php": "^4.0", "guzzlehttp/guzzle": "^7.3", - "kevinrob/guzzle-cache-middleware": "dev-feature-flysystem2", + "kevinrob/guzzle-cache-middleware": "^3.4", "league/flysystem": "^2.1", "m4tthumphrey/php-gitlab-api": "^11.4", "nyholm/psr7": "^1.4", @@ -38,12 +38,6 @@ "phpstan/phpstan-symfony": "^0.12.41", "phpunit/phpunit": "^9.5" }, - "repositories": [ - { - "type": "vcs", - "url": "https://github.com/dpi/guzzle-cache-middleware.git" - } - ], "config": { "sort-packages": true }, diff --git a/src/Commands/Traits/HttpTrait.php b/src/Commands/Traits/HttpTrait.php index 43e09c7..0f63bc6 100644 --- a/src/Commands/Traits/HttpTrait.php +++ b/src/Commands/Traits/HttpTrait.php @@ -4,6 +4,7 @@ namespace dogit\Commands\Traits; +use dogit\Flysystem2Storage; use GuzzleHttp\Client as GuzzleClient; use GuzzleHttp\Cookie\CookieJar; use GuzzleHttp\Cookie\SetCookie; @@ -13,7 +14,6 @@ use Http\Adapter\Guzzle7\Client; use Http\Discovery\Psr17FactoryDiscovery; use Kevinrob\GuzzleCache\CacheMiddleware; -use Kevinrob\GuzzleCache\Storage\Flysystem2Storage; use Kevinrob\GuzzleCache\Strategy\PrivateCacheStrategy; use League\Flysystem\Local\LocalFilesystemAdapter; use Psr\Log\LoggerInterface; diff --git a/src/Flysystem2Storage.php b/src/Flysystem2Storage.php new file mode 100644 index 0000000..fcc2176 --- /dev/null +++ b/src/Flysystem2Storage.php @@ -0,0 +1,70 @@ +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 null; + } + + /** + * {@inheritdoc} + */ + public function save($key, CacheEntry $data) + { + $this->filesystem->write($key, serialize($data)); + + return true; + } + + /** + * {@inheritdoc} + */ + public function delete($key) + { + try { + $this->filesystem->delete($key); + + return true; + } catch (UnableToDeleteFile $ex) { + return false; + } + } +}