1
|
|
|
<?php namespace GeneaLabs\LaravelImagery\Providers; |
2
|
|
|
|
3
|
|
|
use GeneaLabs\LaravelImagery\Imagery; |
4
|
|
|
use GeneaLabs\LaravelImagery\Console\Commands\Clear; |
5
|
|
|
use GeneaLabs\LaravelImagery\Console\Commands\Publish; |
6
|
|
|
use Illuminate\Support\AggregateServiceProvider; |
7
|
|
|
use Intervention\Image\ImageServiceProvider; |
8
|
|
|
|
9
|
|
|
class LaravelImageryService extends AggregateServiceProvider |
10
|
|
|
{ |
11
|
|
|
protected $defer = false; |
12
|
|
|
protected $providers = [ |
13
|
|
|
ImageServiceProvider::class, |
14
|
|
|
]; |
15
|
|
|
|
16
|
|
|
public function boot() |
17
|
|
|
{ |
18
|
|
|
$this->registerBladeDirective('imageryImg', 'img'); |
19
|
|
|
$this->registerBladeDirective('imageryPicture', 'picture'); |
20
|
|
|
|
21
|
|
|
$configPath = __DIR__ . '/../../config/genealabs-laravel-imagery.php'; |
22
|
|
|
$this->publishes([ |
23
|
|
|
$configPath => config_path('genealabs-laravel-imagery.php') |
24
|
|
|
], 'config'); |
25
|
|
|
$this->mergeConfigFrom($configPath, 'genealabs-laravel-imagery'); |
26
|
|
|
|
27
|
|
|
$this->publishes([ |
28
|
|
|
__DIR__ . '/../../public/' => public_path('genealabs-laravel-imagery'), |
29
|
|
|
], 'assets'); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function register() |
33
|
|
|
{ |
34
|
|
|
parent::register(); |
35
|
|
|
|
36
|
|
|
$this->commands(Clear::class); |
37
|
|
|
$this->commands(Publish::class); |
38
|
|
|
$this->app->singleton('imagery', function () { |
39
|
|
|
return new Imagery(); |
40
|
|
|
}); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function provides() : array |
44
|
|
|
{ |
45
|
|
|
return ['genealabs-laravel-imagery']; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
protected function registerBladeDirective(string $directive, string $type) |
49
|
|
|
{ |
50
|
|
|
if (array_key_exists($directive, app('blade.compiler')->getCustomDirectives())) { |
51
|
|
|
throw new Exception("Blade directive '{$directive}' is already registered."); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
app('blade.compiler')->directive($directive, function ($parameters) use ($type) { |
55
|
|
|
$parameters = trim($parameters, "()"); |
56
|
|
|
|
57
|
|
|
return "<?php echo app('imagery')->conjure({$parameters})->{$type}; ?>"; |
58
|
|
|
}); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|