barryvdh / laravel-elfinder

elFinder bundle for Laravel
738 stars 171 forks source link

Calling custom class method from $opts array on upload #250

Open chrisjohnstone opened 5 years ago

chrisjohnstone commented 5 years ago

Thanks for the great package!

I'm trying to save multiple version of each file that is uploaded, each having been resized for responsive delivery on the front-end. Using a standard elfinder example (i.e. no Laravel) you can, following the Logging example (https://github.com/Studio-42/elFinder/wiki/Logging#using-class-instance-callback) achieve this by accessing a separate class and its methods.

However in the example the class is declared in the connector that resides in the vendor's folder and thus should not be modified.

The options array where the relevant custom class and method can be called is available in the elfinder.php config file. I've tried to reference the new class by adding the following to the $opts array:

'bind' => array(
            'upload' => array(new App\Classes\elFinderSimpleLogger(public_path('log.txt')), 'log')
        ),

So far this is unsuccessful. I then thought a ServiceProvider might help in making the class available:

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class CustomElfinderServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }

    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->singleton('App\Classes\elFinderSimpleLogger', function () {
            return new \App\Classes\elFinderSimpleLogger(public_path('log.txt'));
        });
    }
}

But again, this has yielded anything. Is this possible to achieve?