1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-22 13:32:56 +02:00

Add Lumen ServiceProvider

This commit is contained in:
Barry vd. Heuvel
2015-07-09 14:33:43 +02:00
parent ff4f454120
commit 6529068abb

View File

@@ -0,0 +1,81 @@
<?php
namespace Intervention\Image;
use Illuminate\Support\ServiceProvider;
class ImageServiceProviderLumen extends ServiceProvider
{
/**
* Determines if Intervention Imagecache is installed
*
* @return boolean
*/
private function cacheIsInstalled()
{
return class_exists('Intervention\\Image\\ImageCache');
}
/**
* Bootstrap the application events.
*
* @return void
*/
public function boot()
{
// setup intervention/imagecache if package is installed
$this->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));
}
}
}