-
-
Notifications
You must be signed in to change notification settings - Fork 625
Expand file tree
/
Copy pathGlideServiceProvider.php
More file actions
76 lines (63 loc) · 2.2 KB
/
GlideServiceProvider.php
File metadata and controls
76 lines (63 loc) · 2.2 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
76
<?php
namespace Statamic\Providers;
use Illuminate\Support\ServiceProvider;
use Intervention\Image\ImageManager;
use League\Glide\Server;
use Statamic\Contracts\Imaging\ImageManipulator;
use Statamic\Contracts\Imaging\UrlBuilder;
use Statamic\Facades\Config;
use Statamic\Facades\Glide;
use Statamic\Imaging\GlideImageManipulator;
use Statamic\Imaging\GlideUrlBuilder;
use Statamic\Imaging\ImageGenerator;
use Statamic\Imaging\ImageValidator;
use Statamic\Imaging\PresetGenerator;
use Statamic\Imaging\StaticUrlBuilder;
class GlideServiceProvider extends ServiceProvider
{
public $defer = true;
public function register()
{
$this->app->bind(UrlBuilder::class, function () {
return $this->getBuilder();
});
$this->app->bind(ImageManipulator::class, function () {
return new GlideImageManipulator(
$this->app->make(UrlBuilder::class)
);
});
$this->app->singleton(Server::class, function () {
return Glide::server();
});
$this->app->bind(PresetGenerator::class, function ($app) {
return new PresetGenerator(
$app->make(ImageGenerator::class)
);
});
$this->app->bind(ImageValidator::class, function ($app) {
$driver = config('statamic.assets.image_manipulation.driver', 'gd');
$imageManager = match ($driver) {
'gd' => ImageManager::gd(),
'imagick' => ImageManager::imagick(),
default => ImageManager::withDriver($driver),
};
return new ImageValidator($imageManager->driver());
});
}
private function getBuilder()
{
if (Glide::shouldServeDirectly()) {
return new StaticUrlBuilder($this->app->make(ImageGenerator::class), [
'route' => Glide::url(),
]);
}
return new GlideUrlBuilder([
'key' => (Config::get('statamic.assets.image_manipulation.secure')) ? Config::getAppKey() : null,
'route' => Glide::url(),
]);
}
public function provides()
{
return [ImageManipulator::class, Server::class, PresetGenerator::class];
}
}