-
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?
Add Flysystem 2 Storage #138
Conversation
Just upgraded to V2 https://flysystem.thephpleague.com/v2/docs/advanced/upgrade-to-2.0.0/ `use League\Flysystem\AdapterInterface;` => `use League\Flysystem\Local\LocalFilesystemAdapter;` `$this->filesystem->has` => `$this->filesystem->fileExists` `$this->filesystem->put` => `$this->filesystem->write`
Why are you using LocalFilesystemAdapter instead of FilesystemAdapter (Every adapter must implement the League\Flysystem\FilesystemAdapter interface.) says the doc? I think we need an update to Flysystem 2.0 |
I'm not 100% sure if that could be done differently. I just adjusted the existing flysystem implementation according to the docs. https://flysystem.thephpleague.com/v2/docs/adapter/local/ |
Is this going to get merged? |
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.
Few things, this also needs the at least the same level of test coverage as Flysystem 1 version.
README.md
Outdated
@@ -133,6 +135,28 @@ $stack->push( | |||
); | |||
``` | |||
|
|||
for Flysystem 2 |
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.
Either this should be its own ##
heading or the Flysystem 1 version should also get this 'for xxx' heading.
The newer version should be before the older version
If keeping 'for' headings, should be capitalized.
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.
Just added that.
src/Storage/Flysystem2Storage.php
Outdated
*/ | ||
protected $filesystem; | ||
|
||
public function __construct(LocalFilesystemAdapter $adapter) |
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.
I agree with @diego-sorribas this shouldnt be fixed to local
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.
Ok, I 'll try to understand what that means and will fix it.
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.
Ok, I think I got it. :)
Thanks for the hints!
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.
I have honestly no idea how to add testing and how to perform it :/ |
You can add it to |
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 comment
The reason will be displayed to describe this comment to others. Learn more.
The tests doesn't run.
https://github.com/Kevinrob/guzzle-cache-middleware/pull/138/checks?check_run_id=3088224072
There were 2 errors:
1) Kevinrob\GuzzleCache\Tests\PrivateCacheTest::testCacheProvider
Error: Class 'League\Flysystem\Local\LocalFilesystemAdapter' not found
/home/runner/work/guzzle-cache-middleware/guzzle-cache-middleware/tests/PrivateCacheTest.php:38
2) Kevinrob\GuzzleCache\Tests\PublicCacheTest::testCacheProvider
Error: Class 'League\Flysystem\Local\LocalFilesystemAdapter' not found
/home/runner/work/guzzle-cache-middleware/guzzle-cache-middleware/tests/PublicCacheTest.php:106
Maybe, there are something to add to composer.json in require-dev
?
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.
Of course that's missing :). It seems to be not possible to add the same package twice.
This is what I've found: https://stackoverflow.com/questions/35679166/composer-using-two-different-versions-of-guzzle and https://stackoverflow.com/a/56677612/814031
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 comment
The 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.
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.
Adding further changes needed, which was caught by PHPStan static analysis. In summary, return values don't comply with CacheStorageInterface
from this project.
} | ||
} | ||
|
||
return; |
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
*/ | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
\Kevinrob\GuzzleCache\Storage\CacheStorageInterface::save
requires a bool
return value, but \League\Flysystem\Filesystem::write
returns void, and throws exceptions. So this call should be wrapped in try catch and return true/false.
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function delete($key) |
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.
Almost the same as above:
\Kevinrob\GuzzleCache\Storage\CacheStorageInterface::delete
requires a bool
return value, but \League\Flysystem\Filesystem::delete
returns void, and throws exceptions. So you should add a return true
after the ->delete call, and change the return the catch
to return false
Apologies, I'm kind of lost, since this goes deep with the testing and my knowledge here is still rudimentary. |
Flysystem 3 is now a thing ;) |
No description provided.