-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathServiceProvider.php
More file actions
75 lines (67 loc) · 2.27 KB
/
ServiceProvider.php
File metadata and controls
75 lines (67 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
declare(strict_types=1);
namespace Intervention\Image\Laravel;
use Illuminate\Contracts\Routing\ResponseFactory;
use Illuminate\Support\Facades\Response as ResponseFacade;
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
use Intervention\Image\ImageManager;
use Intervention\Image\Interfaces\ImageInterface;
use Illuminate\Http\Response;
use Intervention\Image\FileExtension;
use Intervention\Image\Format;
use Intervention\Image\MediaType;
class ServiceProvider extends BaseServiceProvider
{
/**
* Bootstrap application events
*
* @return void
*/
public function boot()
{
// define config files for publishing
$this->publishes([
__DIR__ . '/../config/image.php' => config_path(Facades\Image::BINDING . '.php')
]);
$this->app->afterResolving(ResponseFactory::class, function (): void {
// register response macro "image"
if ($this->shouldCreateResponseMacro()) {
ResponseFacade::macro(Facades\Image::BINDING, function (
ImageInterface $image,
null|string|Format|MediaType|FileExtension $format = null,
mixed ...$options,
): Response {
return ImageResponseFactory::make($image, $format, ...$options);
});
}
});
}
/**
* Register the image service
*
* @return void
*/
public function register()
{
$this->mergeConfigFrom(
__DIR__ . '/../config/image.php',
Facades\Image::BINDING
);
$this->app->singleton(Facades\Image::BINDING, function () {
return new ImageManager(
driver: config('image.driver'),
autoOrientation: config('image.options.autoOrientation', true),
decodeAnimation: config('image.options.decodeAnimation', true),
blendingColor: config('image.options.blendingColor', 'ffffff'),
strip: config('image.options.strip', false)
);
});
}
/**
* Determine if response macro should be created
*/
private function shouldCreateResponseMacro(): bool
{
return !ResponseFacade::hasMacro(Facades\Image::BINDING);
}
}