-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSuperStaticCacheListener.php
More file actions
executable file
·56 lines (50 loc) · 1.29 KB
/
SuperStaticCacheListener.php
File metadata and controls
executable file
·56 lines (50 loc) · 1.29 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
<?php
namespace Statamic\Addons\SuperStaticCache;
use Statamic\Addons\SuperStaticCache\Service\CacheExclusionChecker;
use Statamic\Addons\SuperStaticCache\Service\CookieManager;
use Statamic\Contracts\Data\Users\User;
use Statamic\Data\Services\UserGroupsService;
use Statamic\Extend\Listener;
use Illuminate\Contracts\Cookie\Factory as CookieFactory;
/**
* Event listeners for the "Super Static Cache" addon.
*/
class SuperStaticCacheListener extends Listener
{
/**
* The events to be listened for, and the methods to call.
*
* @var array
*/
public $events = [
'auth.login' => 'onLogin',
'auth.logout' => 'onLogout',
];
/**
* Set a cookie to skip caching for logged in users.
*
* @param User $user
*/
public function onLogin(User $user)
{
$this->cookieManager()->create($user);
}
/**
* Remove the cookie set on login.
*/
public function onLogout()
{
$this->cookieManager()->delete();
}
/**
* @return CookieManager
*/
private function cookieManager()
{
return new CookieManager(
$this->getConfig(),
new CacheExclusionChecker($this->getConfig(), app(UserGroupsService::class)),
app(CookieFactory::class)
);
}
}