thephpleague / flysystem

Abstraction for local and remote filesystems
https://flysystem.thephpleague.com
MIT License
13.23k stars 825 forks source link

ChainWriter filesystem #1754

Closed antonowano closed 2 months ago

antonowano commented 3 months ago

Feature Request

I propose to implement a file system chain class based on the FilesystemWriter interface. To write and edit files in multiple file systems at once.

Scenario / Use-case

$chain = new ChainWriter();
$chain->addFilesystem(new Filesystem(/* ... */));
$chain->addFilesystem(new Filesystem(/* ... */));
$chain->write('greeting.txt', 'Hello, World!');
frankdejonge commented 3 months ago

In what situation do you intend to use it?

antonowano commented 3 months ago

I think this is a great idea, because when storing the file in several places (local, s3), I only have to configure one chain and do not have to rewrite the code.

frankdejonge commented 3 months ago

Sure, but can you explain what situation you're using it in/for? Is this a migration strategy? Or is it a redundancy strategy? Previously we had an implementation that helped during migrations by self replicating. Writing to multiple locations is only a fraction of the logic behind these types of implementations. And saying "I think it's a great idea" is not providing any context as to the problem you're trying to solve. Also, "storing the file in several places" is a solution to a problem, I'm trying to figure out what problem you're solving.

antonowano commented 3 months ago

The only problem I'm currently solving is the cleanliness of my code. I generate a file and store one copy in local, the other in s3.

frankdejonge commented 3 months ago

Why not hide it behind a function in that case?

antonowano commented 3 months ago

There is no problem with this. Perhaps I formatted the issue incorrectly. This issue is related to the proposal and in my case does not solve any serious problems. But perhaps there will be people whose problems this feature will help solve.

ajgarlag commented 3 months ago

The only problem I'm currently solving is the cleanliness of my code. I generate a file and store one copy in local, the other in s3.

@antonowano Maybe my replicate adapter can help you.

antonowano commented 3 months ago

@antonowano Maybe my replicate adapter can help you.

Interesting solution, I'll definitely take a look!

antonowano commented 3 months ago

@ajgarlag

What differences have I noticed between replication adapter and ChainWriter.

replication adapter is good:

  1. Elegant use via adapter.
  2. Implements both Writer and Reader.
  3. Supports both 3. and 2. versions of flysystem.

ChainWriter is good for:

  1. Does not require any additional packages.
  2. Can accept as many file systems as you like.

Summary

We can bring out the best in everyone and do something new. I want to hear what @frankdejonge has to say about this.