From 6529068abb27b997a79b3f258ca1567185f74d05 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Thu, 9 Jul 2015 14:33:43 +0200 Subject: [PATCH] Add Lumen ServiceProvider --- .../Image/ImageServiceProviderLumen.php | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/Intervention/Image/ImageServiceProviderLumen.php diff --git a/src/Intervention/Image/ImageServiceProviderLumen.php b/src/Intervention/Image/ImageServiceProviderLumen.php new file mode 100644 index 00000000..e9714bb1 --- /dev/null +++ b/src/Intervention/Image/ImageServiceProviderLumen.php @@ -0,0 +1,81 @@ +cacheIsInstalled() ? $this->bootstrapImageCache() : null; + } + + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + $app = $this->app; + + // merge default config + $this->mergeConfigFrom( + __DIR__.'/../../config/config.php', + 'image' + ); + + // create image + $app['image'] = $app->share(function ($app) { + return new ImageManager($app['config']->get('image')); + }); + + $app->alias('image', 'Intervention\Image\ImageManager'); + } + + /** + * Bootstrap imagecache + * + * @return void + */ + private function bootstrapImageCache() + { + $app = $this->app; + $config = __DIR__.'/../../../../imagecache/src/config/config.php'; + + // merge default config + $this->mergeConfigFrom( + $config, + 'imagecache' + ); + + // imagecache route + if (is_string(config('imagecache.route'))) { + + $filename_pattern = '[ \w\\.\\/\\-]+'; + + // route to access template applied image file + $app['router']->get(config('imagecache.route').'/{template}/{filename}', array( + 'uses' => 'Intervention\Image\ImageCacheController@getResponse', + 'as' => 'imagecache' + ))->where(array('filename' => $filename_pattern)); + } + } +}