-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSuperStaticCacheServiceProvider.php
More file actions
executable file
·71 lines (60 loc) · 2.2 KB
/
SuperStaticCacheServiceProvider.php
File metadata and controls
executable file
·71 lines (60 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
<?php
namespace Statamic\Addons\SuperStaticCache;
use Statamic\Addons\SuperStaticCache\Service\CacheExclusionChecker;
use Statamic\Addons\SuperStaticCache\Service\SuperApplicationCacher;
use Statamic\Addons\SuperStaticCache\Service\SuperFileCacher;
use Statamic\Addons\SuperStaticCache\Service\WarmupCacheClient;
use Statamic\Data\Services\UserGroupsService;
use Statamic\Extend\ServiceProvider;
use Statamic\StaticCaching\FileCacher;
use Statamic\StaticCaching\Writer;
use Statamic\StaticCaching\Cacher;
use Illuminate\Cache\Repository;
use Statamic\API\Config;
use Statamic\API\Str;
/**
* Service provider for the "Super Static Cache" addon.
*/
class SuperStaticCacheServiceProvider extends ServiceProvider
{
public function boot()
{
$this->extendCacherService();
$this->app->singleton(WarmupCacheClient::class, function() {
return new WarmupCacheClient($this->getConfig());
});
}
private function extendCacherService()
{
$cache = $this->app->make(Repository::class);
$config = $this->getStaticCachingConfig();
$userGroupsService = $this->app->make(UserGroupsService::class);
$cacheExclusionChecker = new CacheExclusionChecker($this->getConfig(), $userGroupsService);
$request = $this->app->make('request');
if ($this->app[Cacher::class] instanceof FileCacher) {
$cacher = new SuperFileCacher(new Writer, $cache, $config, $request, $cacheExclusionChecker);
} else {
$cacher = new SuperApplicationCacher($cache, $config, $request, $cacheExclusionChecker);
}
$this->app->extend(Cacher::class, function () use ($cacher) {
return $cacher;
});
}
/**
* @return array
*/
private function getStaticCachingConfig()
{
$config = [];
$prefix = 'static_caching_';
foreach (Config::get('caching', []) as $key => $value) {
if (Str::startsWith($key, $prefix)) {
$key = Str::removeLeft($key, $prefix);
$config[$key] = $value;
}
}
$config['base_url'] = $this->app['request']->root();
$config['locale'] = site_locale();
return $config;
}
}