1
|
|
|
<?php namespace Spekkionu\Assetcachebuster; |
2
|
|
|
|
3
|
|
|
use Illuminate\Support\ServiceProvider; |
4
|
|
|
use Spekkionu\Assetcachebuster\HashReplacer\ConfigHashReplacer; |
5
|
|
|
use Spekkionu\Assetcachebuster\Writer\ConfigWriter; |
6
|
|
|
|
7
|
|
|
class AssetcachebusterServiceProvider extends ServiceProvider |
8
|
|
|
{ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Indicates if loading of the provider is deferred. |
12
|
|
|
* |
13
|
|
|
* @var bool |
14
|
|
|
*/ |
15
|
|
|
protected $defer = false; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Bootstrap the application events. |
19
|
|
|
* |
20
|
|
|
* @return void |
21
|
|
|
*/ |
22
|
|
|
public function boot() |
23
|
|
|
{ |
24
|
|
|
$this->publishes([ |
25
|
|
|
dirname(dirname(__DIR__)) . '/config/assetcachebuster.php' => config_path('assetcachebuster.php'), |
26
|
|
|
], 'config'); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Register the service provider. |
31
|
|
|
* |
32
|
|
|
* @return void |
33
|
|
|
*/ |
34
|
|
|
public function register() |
35
|
|
|
{ |
36
|
|
|
|
37
|
|
|
$this->mergeConfigFrom( |
38
|
|
|
dirname(dirname(__DIR__)) . '/config/assetcachebuster.php', 'assetcachebuster' |
39
|
|
|
); |
40
|
|
|
|
41
|
|
|
$this->app->singleton('assetcachebuster', function () { |
42
|
|
|
$options = [ |
43
|
|
|
'enable' => $this->app['config']->get('assetcachebuster.enable'), |
44
|
|
|
'hash' => $this->app['config']->get('assetcachebuster.hash'), |
45
|
|
|
'cdn' => $this->app['config']->get('assetcachebuster.cdn'), |
46
|
|
|
'prefix' => $this->app['config']->get('assetcachebuster.prefix'), |
47
|
|
|
]; |
48
|
|
|
|
49
|
|
|
return new Assetcachebuster($options); |
50
|
|
|
}); |
51
|
|
|
|
52
|
|
|
$this->app->bind('Spekkionu\Assetcachebuster\Writer\ConfigWriter', function(){ |
53
|
|
|
return new ConfigWriter($this->app->make('Illuminate\Filesystem\Filesystem'), $this->app->make('path.config')); |
54
|
|
|
}); |
55
|
|
|
|
56
|
|
|
$this->app->bind('Spekkionu\Assetcachebuster\Writer\WriterInterface', 'Spekkionu\Assetcachebuster\Writer\ConfigWriter'); |
57
|
|
|
|
58
|
|
|
$this->app->bind('Spekkionu\Assetcachebuster\HashReplacer\ConfigHashReplacer', function(){ |
59
|
|
|
return new ConfigHashReplacer($this->app->make('assetcachebuster'), $this->app->make('Spekkionu\Assetcachebuster\Writer\WriterInterface')); |
60
|
|
|
}); |
61
|
|
|
|
62
|
|
|
$this->app->bind('Spekkionu\Assetcachebuster\HashReplacer\HashReplacerInterface', 'Spekkionu\Assetcachebuster\HashReplacer\ConfigHashReplacer'); |
63
|
|
|
|
64
|
|
|
// Register artisan command |
65
|
|
|
$this->app->singleton( |
66
|
|
|
'command.assetcachebuster.generate', |
67
|
|
|
function () { |
68
|
|
|
return new Console\GenerateCommand($this->app->make('Spekkionu\Assetcachebuster\HashReplacer\HashReplacerInterface'), $this->app->make('Illuminate\Contracts\Config\Repository')); |
69
|
|
|
} |
70
|
|
|
); |
71
|
|
|
$this->commands( |
72
|
|
|
'command.assetcachebuster.generate' |
73
|
|
|
); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Get the services provided by the provider. |
78
|
|
|
* |
79
|
|
|
* @return array |
80
|
|
|
*/ |
81
|
|
|
public function provides() |
82
|
|
|
{ |
83
|
|
|
return array( |
84
|
|
|
'assetcachebuster', |
85
|
|
|
'command.assetcachebuster.generate', |
86
|
|
|
'Spekkionu\Assetcachebuster\Writer\ConfigWriter', |
87
|
|
|
'Spekkionu\Assetcachebuster\Writer\WriterInterface', |
88
|
|
|
'Spekkionu\Assetcachebuster\HashReplacer\ConfigHashReplacer', |
89
|
|
|
'Spekkionu\Assetcachebuster\HashReplacer\HashReplacerInterface', |
90
|
|
|
); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|