okaybueno /
images
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace OkayBueno\Images; |
||||
| 4 | |||||
| 5 | use Illuminate\Support\ServiceProvider; |
||||
| 6 | use Intervention\Image\ImageManager; |
||||
| 7 | use OkayBueno\Images\Services\ImageServiceInterface; |
||||
| 8 | use OkayBueno\Images\Services\ImageProcessingServiceInterface; |
||||
| 9 | use OkayBueno\Images\Services\src\ImageProcessingService; |
||||
| 10 | use OkayBueno\Images\Services\src\ImageService; |
||||
| 11 | use OkayBueno\Images\Services\Validation\ImageValidatorInterface; |
||||
| 12 | use OkayBueno\Images\Services\Validation\src\ImageValidatorLaravel; |
||||
| 13 | |||||
| 14 | /** |
||||
| 15 | * Class ImagingServiceProvider |
||||
| 16 | * @package OkayBueno\Images |
||||
| 17 | */ |
||||
| 18 | class ImageServiceProvider extends ServiceProvider |
||||
| 19 | { |
||||
| 20 | |||||
| 21 | private $configPath = '/config/images.php'; |
||||
| 22 | |||||
| 23 | |||||
| 24 | /** |
||||
| 25 | * |
||||
| 26 | */ |
||||
| 27 | public function boot() |
||||
| 28 | { |
||||
| 29 | $this->publishes([ |
||||
| 30 | __DIR__.$this->configPath => config_path('images.php'), |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 31 | ], 'images'); |
||||
| 32 | |||||
| 33 | $this->loadMigrationsFrom( __DIR__.'/migrations' ); |
||||
| 34 | } |
||||
| 35 | |||||
| 36 | |||||
| 37 | /** |
||||
| 38 | * |
||||
| 39 | */ |
||||
| 40 | public function register() |
||||
| 41 | { |
||||
| 42 | // merge default config |
||||
| 43 | $this->mergeConfigFrom( |
||||
| 44 | __DIR__.$this->configPath , 'images' |
||||
| 45 | ); |
||||
| 46 | |||||
| 47 | // Bindings. |
||||
| 48 | $this->bindValidators(); |
||||
| 49 | $this->bindImageProcessor(); |
||||
| 50 | $this->bindImageService(); |
||||
| 51 | |||||
| 52 | $this->loadHelpers(); |
||||
| 53 | |||||
| 54 | // And commands. |
||||
| 55 | $this->registerPurgeImagesCommand(); |
||||
| 56 | $this->registerResizeImageCommand(); |
||||
| 57 | } |
||||
| 58 | |||||
| 59 | |||||
| 60 | /** |
||||
| 61 | * |
||||
| 62 | */ |
||||
| 63 | private function bindImageProcessor() |
||||
| 64 | { |
||||
| 65 | // Bind the image processing service. |
||||
| 66 | $this->app->bind( ImageProcessingServiceInterface::class, function ( $app ) |
||||
|
0 ignored issues
–
show
The parameter
$app is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||
| 67 | { |
||||
| 68 | // create an image manager instance with favored driver |
||||
| 69 | $config = [ |
||||
| 70 | 'driver' => config('images.driver', 'gd') |
||||
|
0 ignored issues
–
show
The function
config was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 71 | ]; |
||||
| 72 | |||||
| 73 | $imageManager = new ImageManager( $config ); |
||||
| 74 | |||||
| 75 | return new ImageProcessingService( $imageManager ); |
||||
| 76 | }); |
||||
| 77 | } |
||||
| 78 | |||||
| 79 | /** |
||||
| 80 | * |
||||
| 81 | */ |
||||
| 82 | private function bindValidators() |
||||
| 83 | { |
||||
| 84 | // Bind the image service. |
||||
| 85 | $this->app->bind( ImageValidatorInterface::class, function ( $app ) |
||||
| 86 | { |
||||
| 87 | return $app->make( ImageValidatorLaravel::class ); |
||||
| 88 | }); |
||||
| 89 | } |
||||
| 90 | |||||
| 91 | /** |
||||
| 92 | * |
||||
| 93 | */ |
||||
| 94 | private function bindImageService() |
||||
| 95 | { |
||||
| 96 | // Bind the image service. |
||||
| 97 | $this->app->bind( ImageServiceInterface::class, function ( $app ) |
||||
| 98 | { |
||||
| 99 | return $app->make( ImageService::class ); |
||||
| 100 | }); |
||||
| 101 | } |
||||
| 102 | |||||
| 103 | /** |
||||
| 104 | * |
||||
| 105 | */ |
||||
| 106 | private function loadHelpers() |
||||
| 107 | { |
||||
| 108 | foreach (glob(__DIR__.'/Helpers/*.php') as $filename) require_once( $filename ); |
||||
| 109 | } |
||||
| 110 | |||||
| 111 | |||||
| 112 | /** |
||||
| 113 | * |
||||
| 114 | */ |
||||
| 115 | private function registerPurgeImagesCommand() |
||||
| 116 | { |
||||
| 117 | $this->app->singleton('command.images.purge-deleted-images', function ($app) |
||||
| 118 | { |
||||
| 119 | return $app[ \OkayBueno\Images\Commands\PurgeDeletedImages::class ]; |
||||
| 120 | }); |
||||
| 121 | |||||
| 122 | $this->commands('command.images.purge-deleted-images'); |
||||
| 123 | } |
||||
| 124 | |||||
| 125 | /** |
||||
| 126 | * |
||||
| 127 | */ |
||||
| 128 | private function registerResizeImageCommand() |
||||
| 129 | { |
||||
| 130 | $this->app->singleton('command.images.resize-image', function ($app) |
||||
| 131 | { |
||||
| 132 | return $app[ \OkayBueno\Images\Commands\ResizeImage::class ]; |
||||
| 133 | }); |
||||
| 134 | |||||
| 135 | $this->commands('command.images.resize-image'); |
||||
| 136 | } |
||||
| 137 | |||||
| 138 | |||||
| 139 | } |