Skip to content

Add Flysystem 2 Storage#138

Closed
marcus-at-localhost wants to merge 9 commits intoKevinrob:masterfrom
marcus-at-localhost:feature-flysystem2
Closed

Add Flysystem 2 Storage#138
marcus-at-localhost wants to merge 9 commits intoKevinrob:masterfrom
marcus-at-localhost:feature-flysystem2

Conversation

@marcus-at-localhost
Copy link
Copy Markdown

No description provided.

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`
@diego-sorribas
Copy link
Copy Markdown

diego-sorribas commented Feb 17, 2021

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

@marcus-at-localhost
Copy link
Copy Markdown
Author

Why are you using LocalFilesystemAdapter instead of FilesystemAdapter (Every adapter must implement the League\Flysystem\FilesystemAdapter interface.) says the doc?

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/

@marcus-at-localhost
Copy link
Copy Markdown
Author

Is this going to get merged?

Copy link
Copy Markdown

@dpi dpi left a 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.

Comment thread README.md Outdated
);
```

for Flysystem 2
Copy link
Copy Markdown

@dpi dpi Jun 26, 2021

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just added that.

Comment thread src/Storage/Flysystem2Storage.php Outdated
*/
protected $filesystem;

public function __construct(LocalFilesystemAdapter $adapter)
Copy link
Copy Markdown

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

Copy link
Copy Markdown
Author

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.

Copy link
Copy Markdown
Author

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!

@marcus-at-localhost marcus-at-localhost changed the title Add Flysystem 2 Storage Add Flysystem 1 Heading Jun 26, 2021
@marcus-at-localhost marcus-at-localhost changed the title Add Flysystem 1 Heading Add Flysystem 2 Storage Jun 26, 2021
Copy link
Copy Markdown
Owner

@Kevinrob Kevinrob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this addition!

Can you please:

  • Add a test for it
  • Respond to @dpi comment

@marcus-at-localhost
Copy link
Copy Markdown
Author

I have honestly no idea how to add testing and how to perform it :/

@Kevinrob
Copy link
Copy Markdown
Owner

I have honestly no idea how to add testing and how to perform it :/

You can add it to PrivateCacheTest and PublicCacheTest in $cacheProviders like FlysystemStorage 👌

use Kevinrob\GuzzleCache\Storage\VolatileRuntimeStorage;
use Kevinrob\GuzzleCache\Strategy\PrivateCacheStrategy;
use League\Flysystem\Adapter\Local;
use League\Flysystem\Local\LocalFilesystemAdapter;
Copy link
Copy Markdown
Owner

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?

Copy link
Copy Markdown
Author

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.

Copy link
Copy Markdown

@dpi dpi Jul 18, 2021

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.

Copy link
Copy Markdown

@dpi dpi left a 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;
Copy link
Copy Markdown

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));
Copy link
Copy Markdown

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)
Copy link
Copy Markdown

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

@dpi
Copy link
Copy Markdown

dpi commented Jul 23, 2021

Changes can be based off https://github.com/dpi/dogit/pull/2/files#diff-807a9ba3b18ae226d5e918d14500c7503f96864c697a8d97a8fdb3396312ff97R19

@marcus-at-localhost
Copy link
Copy Markdown
Author

Apologies, I'm kind of lost, since this goes deep with the testing and my knowledge here is still rudimentary.
Is it possible for someone else to add/merge those proposed changes so it passes all tests?
I would really appreciate that.

@dpi
Copy link
Copy Markdown

dpi commented Feb 19, 2022

Flysystem 3 is now a thing ;)

@Kevinrob
Copy link
Copy Markdown
Owner

Kevinrob commented Aug 1, 2025

#182 merged with Flysystem 3

@Kevinrob Kevinrob closed this Aug 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants