44
55use Illuminate \Support \Facades \Route ;
66use Illuminate \Support \ServiceProvider ;
7+ use Intervention \Image \Drivers \Gd \Driver as GdDriver ;
8+ use Intervention \Image \Drivers \Imagick \Driver as ImagickDriver ;
9+ use Intervention \Image \ImageManager ;
10+ use Intervention \Image \Interfaces \ImageManagerInterface ;
11+ use UniSharp \LaravelFilemanager \Services \ImageService ;
712
813/**
914 * Class LaravelFilemanagerServiceProvider.
@@ -17,24 +22,24 @@ class LaravelFilemanagerServiceProvider extends ServiceProvider
1722 */
1823 public function boot ()
1924 {
20- $ this ->loadTranslationsFrom (__DIR__ . '/lang ' , 'laravel-filemanager ' );
25+ $ this ->loadTranslationsFrom (__DIR__ . '/lang ' , 'laravel-filemanager ' );
2126
22- $ this ->loadViewsFrom (__DIR__ . '/views ' , 'laravel-filemanager ' );
27+ $ this ->loadViewsFrom (__DIR__ . '/views ' , 'laravel-filemanager ' );
2328
2429 $ this ->publishes ([
2530 __DIR__ . '/config/lfm.php ' => base_path ('config/lfm.php ' ),
2631 ], 'lfm_config ' );
2732
2833 $ this ->publishes ([
29- __DIR__ . '/../public ' => public_path ('vendor/laravel-filemanager ' ),
34+ __DIR__ . '/../public ' => public_path ('vendor/laravel-filemanager ' ),
3035 ], 'lfm_public ' );
3136
3237 $ this ->publishes ([
33- __DIR__ . '/views ' => base_path ('resources/views/vendor/laravel-filemanager ' ),
38+ __DIR__ . '/views ' => base_path ('resources/views/vendor/laravel-filemanager ' ),
3439 ], 'lfm_view ' );
3540
3641 $ this ->publishes ([
37- __DIR__ . '/Handlers/LfmConfigHandler.php ' => base_path ('app/Handlers/LfmConfigHandler.php ' ),
42+ __DIR__ . '/Handlers/LfmConfigHandler.php ' => base_path ('app/Handlers/LfmConfigHandler.php ' ),
3843 ], 'lfm_handler ' );
3944
4045 if (config ('lfm.use_package_routes ' )) {
@@ -51,10 +56,31 @@ public function boot()
5156 */
5257 public function register ()
5358 {
54- $ this ->mergeConfigFrom (__DIR__ . '/config/lfm.php ' , 'lfm-config ' );
59+ $ this ->mergeConfigFrom (__DIR__ . '/config/lfm.php ' , 'lfm ' );
5560
5661 $ this ->app ->singleton ('laravel-filemanager ' , function () {
5762 return true ;
5863 });
64+
65+ $ this ->app ->singleton (ImageManagerInterface::class, function ($ app ) {
66+ $ driver = config ('lfm.intervention_driver ' );
67+
68+ $ driverInstance = match ($ driver ) {
69+ 'gd ' => new GdDriver (),
70+ 'imagick ' => new ImagickDriver (),
71+ default => null ,
72+ };
73+
74+ if (is_null ($ driverInstance )) {
75+ \Log::error ("Unsupported image driver [ $ driver]. GdDriver will be used. " );
76+ $ driverInstance = new GdDriver ();
77+ }
78+
79+ return new ImageManager ($ driverInstance );
80+ });
81+
82+ $ this ->app ->singleton (ImageService::class, function ($ app ) {
83+ return new ImageService ($ app ->make (ImageManagerInterface::class));
84+ });
5985 }
6086}
0 commit comments