GrahamCampbell/Laravel-Flysystem

Add a plugin

fridzema opened this issue · 5 comments

Hello,

I was curious is there is any "clean" way for me to add a plugin to your/flysystem package.
I want to add the GetWithMetadata, but don't know what is the best way to achieve this.

I hope you can help me out :)

Thanks for getting in touch. I'll have a think about this, and get back to you. I've never tried to do this before actually. :)

I just ran into the same problem on my project. Has any progress been made to this so far?

For my solution, I added a PluginManager to the FlysystemFactory that would hold onto instances of different plugins and be similar to the Config\Repository from Laravel, but much simplified. Along with this I added plugins as a configuration value both on the Flysystem global level and inside of each driver. Within the make call on the factory, I would just addPlugin for each configured plugin, pulling the instance from the PluginManager. In reality, I am just making a Container out of the PluginManager, so the Laravel system could be used. However, most of the classes in this project seemed to be self contained, so I attempted to follow the pattern in my own implementation.

I'd be happy to attempt a PR with this pattern. I'd also be open to discussing other options. It would be very helpful to get something together so that I can remove these extra classes from my project.

This is what I did...

public function boot()
    {
        foreach (config('filesystems.disks') as $key=>$config) {
	        if ($key != 'public')
		        Storage::disk($key)->addPlugin(new Plugin);
        }
        
    }

Might not be the best, but it worked.

@GrahamCampbell @camuthig @roblesterjr04
Thanks for the suggestions and helping me with this!
I have fixed it with a workaround via the Laravel storage API, works good for me.

@roblesterjr04 That code there is not for this package.