1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spatie\ResponseCache; |
4
|
|
|
|
5
|
|
|
use Illuminate\Cache\Repository; |
6
|
|
|
use Illuminate\Container\Container; |
7
|
|
|
use Illuminate\Support\ServiceProvider; |
8
|
|
|
use Spatie\ResponseCache\CacheProfiles\CacheProfile; |
9
|
|
|
use Spatie\ResponseCache\Commands\ClearCommand; |
10
|
|
|
use Spatie\ResponseCache\Hasher\RequestHasher; |
11
|
|
|
use Spatie\ResponseCache\Serializers\Serializer; |
12
|
|
|
|
13
|
|
|
class ResponseCacheServiceProvider extends ServiceProvider |
14
|
|
|
{ |
15
|
|
|
public function boot() |
16
|
|
|
{ |
17
|
|
|
$this->publishes([ |
18
|
|
|
__DIR__.'/../config/responsecache.php' => config_path('responsecache.php'), |
19
|
|
|
], 'config'); |
20
|
|
|
|
21
|
|
|
$this->app->bind(CacheProfile::class, function (Container $app) { |
22
|
|
|
return $app->make(config('responsecache.cache_profile')); |
23
|
|
|
}); |
24
|
|
|
|
25
|
|
|
$this->app->bind(RequestHasher::class, function (Container $app) { |
26
|
|
|
return $app->make(config('responsecache.hasher')); |
27
|
|
|
}); |
28
|
|
|
|
29
|
|
|
$this->app->bind(Serializer::class, function (Container $app) { |
30
|
|
|
return $app->make(config('responsecache.serializer')); |
31
|
|
|
}); |
32
|
|
|
|
33
|
|
|
$this->app->when(ResponseCacheRepository::class) |
34
|
|
|
->needs(Repository::class) |
35
|
|
|
->give(function (): Repository { |
36
|
|
|
$repository = app('cache')->store(config('responsecache.cache_store')); |
37
|
|
|
if (! empty(config('responsecache.cache_tag'))) { |
38
|
|
|
return $repository->tags(config('responsecache.cache_tag')); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
return $repository; |
42
|
|
|
}); |
43
|
|
|
|
44
|
|
|
$this->app->singleton('responsecache', ResponseCache::class); |
45
|
|
|
|
46
|
|
|
if ($this->app->runningInConsole()) { |
47
|
|
|
$this->commands([ |
48
|
|
|
ClearCommand::class, |
49
|
|
|
]); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function register() |
54
|
|
|
{ |
55
|
|
|
$this->mergeConfigFrom(__DIR__.'/../config/responsecache.php', 'responsecache'); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|