1
0

ImageServiceProviderLaravel5.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace Intervention\Image;
  3. use Illuminate\Support\ServiceProvider;
  4. class ImageServiceProviderLaravel5 extends ServiceProvider
  5. {
  6. /**
  7. * Determines if Intervention Imagecache is installed
  8. *
  9. * @return boolean
  10. */
  11. private function cacheIsInstalled()
  12. {
  13. return class_exists('Intervention\\Image\\ImageCache');
  14. }
  15. /**
  16. * Bootstrap the application events.
  17. *
  18. * @return void
  19. */
  20. public function boot()
  21. {
  22. $this->publishes([
  23. __DIR__.'/../../config/config.php' => config_path('image.php')
  24. ]);
  25. // setup intervention/imagecache if package is installed
  26. $this->cacheIsInstalled() ? $this->bootstrapImageCache() : null;
  27. }
  28. /**
  29. * Register the service provider.
  30. *
  31. * @return void
  32. */
  33. public function register()
  34. {
  35. $app = $this->app;
  36. // merge default config
  37. $this->mergeConfigFrom(
  38. __DIR__.'/../../config/config.php',
  39. 'image'
  40. );
  41. // create image
  42. $app->singleton('image', function ($app) {
  43. return new ImageManager($app['config']->get('image'));
  44. });
  45. $app->alias('image', 'Intervention\Image\ImageManager');
  46. }
  47. /**
  48. * Bootstrap imagecache
  49. *
  50. * @return void
  51. */
  52. private function bootstrapImageCache()
  53. {
  54. $app = $this->app;
  55. $config = __DIR__.'/../../../../imagecache/src/config/config.php';
  56. $this->publishes([
  57. $config => config_path('imagecache.php')
  58. ]);
  59. // merge default config
  60. $this->mergeConfigFrom(
  61. $config,
  62. 'imagecache'
  63. );
  64. // imagecache route
  65. if (is_string(config('imagecache.route'))) {
  66. $filename_pattern = '[ \w\\.\\/\\-\\@\(\)]+';
  67. // route to access template applied image file
  68. $app['router']->get(config('imagecache.route').'/{template}/{filename}', [
  69. 'uses' => 'Intervention\Image\ImageCacheController@getResponse',
  70. 'as' => 'imagecache'
  71. ])->where(['filename' => $filename_pattern]);
  72. }
  73. }
  74. }