|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Hassan\S3BrowserBasedUploads; |
| 4 | + |
| 5 | +use Illuminate\Support\ServiceProvider as BaseServiceProvider; |
| 6 | +use League\Flysystem\AwsS3v3\AwsS3Adapter; |
| 7 | + |
| 8 | +class ServiceProvider extends BaseServiceProvider |
| 9 | +{ |
| 10 | + /** |
| 11 | + * Bootstrap the application services. |
| 12 | + */ |
| 13 | + public function boot() |
| 14 | + { |
| 15 | + if ($this->app->runningInConsole()) { |
| 16 | + $this->publishes([ |
| 17 | + __DIR__.'/../config/config.php' => config_path('s3-browser-based-uploads.php'), |
| 18 | + ], 'config'); |
| 19 | + } |
| 20 | + } |
| 21 | + |
| 22 | + protected function getS3Adapter() : AwsS3Adapter |
| 23 | + { |
| 24 | + return $this->app['filesystem']->disk($this->getConfig('disk'))->getAdapter(); |
| 25 | + } |
| 26 | + |
| 27 | + protected function getInputs() : array |
| 28 | + { |
| 29 | + return $this->getConfig('inputs', []); |
| 30 | + } |
| 31 | + |
| 32 | + protected function getConditions() : array |
| 33 | + { |
| 34 | + return $this->getConfig('conditions', []); |
| 35 | + } |
| 36 | + |
| 37 | + protected function getExpirationTime() : string |
| 38 | + { |
| 39 | + return $this->getConfig('expiration_time', '+5 minutes'); |
| 40 | + } |
| 41 | + |
| 42 | + public function getConfig(string $key, $default = null) |
| 43 | + { |
| 44 | + return config('s3-browser-based-uploads.providers.default.' . $key, $default); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * Register the application services. |
| 49 | + */ |
| 50 | + public function register() |
| 51 | + { |
| 52 | + $this->mergeConfigFrom(__DIR__.'/../config/config.php', 's3-browser-based-uploads'); |
| 53 | + |
| 54 | + $this->app->bind(S3BrowserBasedUploadsManager::class, function () { |
| 55 | + $adapter = $this->getS3Adapter(); |
| 56 | + |
| 57 | + return new S3BrowserBasedUploadsManager( |
| 58 | + $adapter->getClient(), |
| 59 | + $adapter->getBucket(), |
| 60 | + $this->getInputs(), |
| 61 | + $this->getConditions(), |
| 62 | + $this->getExpirationTime() |
| 63 | + ); |
| 64 | + }); |
| 65 | + |
| 66 | + $this->app->alias(S3BrowserBasedUploadsManager::class, 's3-browser-based-uploads'); |
| 67 | + } |
| 68 | +} |
0 commit comments