File indexing completed on 2025-01-26 05:29:15

0001 <?php
0002 
0003 namespace Intervention\Image;
0004 
0005 use Illuminate\Support\ServiceProvider;
0006 
0007 class ImageServiceProviderLaravel5 extends ServiceProvider
0008 {
0009     /**
0010      * Determines if Intervention Imagecache is installed
0011      *
0012      * @return boolean
0013      */
0014     private function cacheIsInstalled()
0015     {
0016         return class_exists('Intervention\\Image\\ImageCache');
0017     }
0018 
0019     /**
0020      * Bootstrap the application events.
0021      *
0022      * @return void
0023      */
0024     public function boot()
0025     {
0026         $this->publishes([
0027             __DIR__.'/../../config/config.php' => config_path('image.php')
0028         ]);
0029 
0030         // setup intervention/imagecache if package is installed
0031         $this->cacheIsInstalled() ? $this->bootstrapImageCache() : null;
0032     }
0033 
0034     /**
0035      * Register the service provider.
0036      *
0037      * @return void
0038      */
0039     public function register()
0040     {
0041         $app = $this->app;
0042 
0043         // merge default config
0044         $this->mergeConfigFrom(
0045             __DIR__.'/../../config/config.php',
0046             'image'
0047         );
0048 
0049         // create image
0050         $app->singleton('image', function ($app) {
0051             return new ImageManager($app['config']->get('image'));
0052         });
0053 
0054         $app->alias('image', 'Intervention\Image\ImageManager');
0055     }
0056 
0057     /**
0058      * Bootstrap imagecache
0059      *
0060      * @return void
0061      */
0062     private function bootstrapImageCache()
0063     {
0064         $app = $this->app;
0065         $config = __DIR__.'/../../../../imagecache/src/config/config.php';
0066 
0067         $this->publishes([
0068             $config => config_path('imagecache.php')
0069         ]);
0070 
0071         // merge default config
0072         $this->mergeConfigFrom(
0073             $config,
0074             'imagecache'
0075         );
0076 
0077         // imagecache route
0078         if (is_string(config('imagecache.route'))) {
0079 
0080             $filename_pattern = '[ \w\\.\\/\\-\\@\(\)]+';
0081 
0082             // route to access template applied image file
0083             $app['router']->get(config('imagecache.route').'/{template}/{filename}', [
0084                 'uses' => 'Intervention\Image\ImageCacheController@getResponse',
0085                 'as' => 'imagecache'
0086             ])->where(['filename' => $filename_pattern]);
0087         }
0088     }
0089 }