| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Spatie\MediaLibrary; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Illuminate\Filesystem\Filesystem as IlluminateFilesystem; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Illuminate\Support\Collection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Illuminate\Support\ServiceProvider; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Spatie\MediaLibrary\Commands\CleanCommand; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Spatie\MediaLibrary\Commands\ClearCommand; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Spatie\MediaLibrary\Commands\RegenerateCommand; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Spatie\MediaLibrary\Filesystem\Filesystem; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Spatie\MediaLibrary\ResponsiveImages\TinyPlaceholderGenerator\TinyPlaceholderGenerator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Spatie\MediaLibrary\ResponsiveImages\WidthCalculator\WidthCalculator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | class MediaLibraryServiceProvider extends ServiceProvider | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     public function boot(IlluminateFilesystem $filesystem) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |         $this->publishes([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |             __DIR__.'/../config/medialibrary.php' => config_path('medialibrary.php'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |         ], 'config'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         $this->publishes([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |             __DIR__.'/../database/migrations/create_media_table.php.stub' => $this->getMigrationFileName($filesystem), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         ], 'migrations'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         $this->publishes([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |             __DIR__.'/../resources/views' => resource_path('views/vendor/medialibrary'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         ], 'views'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         $mediaClass = config('medialibrary.media_model'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $mediaClass::observe(new MediaObserver()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         $this->loadViewsFrom(__DIR__.'/../resources/views', 'medialibrary'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     public function register() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         $this->mergeConfigFrom(__DIR__.'/../config/medialibrary.php', 'medialibrary'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $this->app->singleton(MediaRepository::class, function () { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |             $mediaClass = config('medialibrary.media_model'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |             return new MediaRepository(new $mediaClass); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $this->app->bind('command.medialibrary:regenerate', RegenerateCommand::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         $this->app->bind('command.medialibrary:clear', ClearCommand::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $this->app->bind('command.medialibrary:clean', CleanCommand::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         $this->app->bind(Filesystem::class, Filesystem::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $this->app->bind(WidthCalculator::class, config('medialibrary.responsive_images.width_calculator')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $this->app->bind(TinyPlaceholderGenerator::class, config('medialibrary.responsive_images.tiny_placeholder_generator')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $this->commands([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |             'command.medialibrary:regenerate', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             'command.medialibrary:clear', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             'command.medialibrary:clean', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         $this->registerDeprecatedConfig(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     protected function registerDeprecatedConfig() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         if (! config('medialibrary.disk_name')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |             config(['medialibrary.disk_name' => config('medialibrary.default_filesystem')]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 73 |  |  |     protected function getMigrationFileName(IlluminateFilesystem $filesystem) | 
            
                                                        
            
                                    
            
            
                | 74 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 75 |  |  |         $timestamp = date('Y_m_d_His'); | 
            
                                                        
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 77 |  |  |         return Collection::make($this->app->databasePath().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR) | 
            
                                                        
            
                                    
            
            
                | 78 |  |  |             ->flatMap(function ($path) use ($filesystem) { | 
            
                                                        
            
                                    
            
            
                | 79 |  |  |                 return $filesystem->glob($path.'*_create_media_table.php'); | 
            
                                                        
            
                                    
            
            
                | 80 |  |  |             })->push($this->app->databasePath()."/migrations/{$timestamp}_create_media_table.php") | 
            
                                                        
            
                                    
            
            
                | 81 |  |  |             ->first(); | 
            
                                                        
            
                                    
            
            
                | 82 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 83 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 84 |  |  |  |