Example #1
0
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     // Merges package config with user config
     $this->mergeConfigFrom(__DIR__ . '/../config/config.php', 'upchuck');
     // Instantiate helpers
     $this->app->singleton('upchuck', function ($app) {
         return new Helpers($app['config']->get('upchuck'));
     });
     // Instantiate the disk for the tmp directory, where the image was uploaded
     $this->app->singleton('upchuck.tmp', function ($app) {
         $tmp = ini_get('upload_tmp_dir') ?: sys_get_temp_dir();
         return new Filesystem(new LocalAdapter($tmp));
     });
     // Instantiate the disk for the destination
     $this->app->singleton('upchuck.disk', function ($app) {
         // Build GrahamCampbell\Flysystem's factory for making Flysystem instances
         $adapter = new AdapterFactory();
         $cache = new CacheFactory($app['cache']);
         $factory = new FlysystemFactory($adapter, $cache);
         // Make an instance of this package's subclass of GrahamCampbell\Flysystem's
         // Manager class that creates connections given configs.
         $manager = new Manager($app['config'], $factory);
         // Massage the Upchuck config to what GrahamCampbell\Flysystem is expecting
         return $factory->make($manager->getConnectionConfig(), $manager);
     });
     // Instantiate Flysystem's manager for this package
     $this->app->singleton('upchuck.manager', function ($app) {
         return new MountManager(['tmp' => $app['upchuck.tmp'], 'disk' => $app['upchuck.disk']]);
     });
     // Instantiate observer which handles model save / delete and delegates
     // out the saving of files
     $this->app->singleton('upchuck.observer', function ($app) {
         return new Observer($app['upchuck.storage']);
     });
     // Instantiate storage class
     $this->app->singleton('upchuck.storage', function ($app) {
         return new Storage($app['upchuck.manager'], $app['upchuck']);
     });
 }
 /**
  * Create the connection instance.
  *
  * @param array $config
  *
  * @return \League\Flysystem\FilesystemInterface
  */
 protected function createConnection(array $config)
 {
     return $this->factory->make($config, $this);
 }