1
|
|
|
<?php |
2
|
|
|
namespace Ubiquity\security\acl\persistence; |
3
|
|
|
|
4
|
|
|
use Ubiquity\cache\CacheManager; |
5
|
|
|
use Ubiquity\security\acl\models\AbstractAclPart; |
6
|
|
|
use Ubiquity\security\acl\models\AclElement; |
7
|
|
|
use Ubiquity\security\acl\models\Role; |
8
|
|
|
use Ubiquity\security\acl\models\Resource; |
9
|
|
|
use Ubiquity\security\acl\models\Permission; |
10
|
|
|
use Ubiquity\security\acl\cache\traits\AclCacheTrait; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Ubiquity\security\acl\persistence$AclCacheProvider |
14
|
|
|
* This class is part of Ubiquity |
15
|
|
|
* |
16
|
|
|
* @author jc |
17
|
|
|
* @version 1.0.0 |
18
|
|
|
* |
19
|
|
|
*/ |
20
|
|
|
class AclCacheProvider extends AclArrayProvider { |
21
|
|
|
use AclCacheTrait; |
22
|
|
|
|
23
|
6 |
|
public function __construct() { |
24
|
6 |
|
$cacheKeys = $this->getCacheKeys(); |
25
|
6 |
|
foreach ($cacheKeys as $key) { |
26
|
6 |
|
$this->createCache($key); |
27
|
|
|
} |
28
|
|
|
} |
29
|
|
|
|
30
|
6 |
|
protected function getCacheKeys(): array { |
31
|
6 |
|
return [ |
32
|
6 |
|
$this->getRootKey('acls'), |
33
|
6 |
|
$this->getRootKey(Role::class), |
34
|
6 |
|
$this->getRootKey(Resource::class), |
35
|
6 |
|
$this->getRootKey(Permission::class) |
36
|
6 |
|
]; |
37
|
|
|
} |
38
|
|
|
|
39
|
6 |
|
protected function loadAllPart($class): array { |
40
|
6 |
|
$this->parts[$class] = CacheManager::$cache->fetch($this->getRootKey($class)); |
41
|
6 |
|
return parent::loadAllPart($class); |
42
|
|
|
} |
43
|
|
|
|
44
|
6 |
|
public function loadAllAcls(): array { |
45
|
6 |
|
$this->aclsArray = CacheManager::$cache->fetch($this->getRootKey('acls')); |
46
|
6 |
|
return parent::loadAllAcls(); |
47
|
|
|
} |
48
|
|
|
|
49
|
3 |
|
public function isAutosave(): bool { |
50
|
3 |
|
return false; |
51
|
|
|
} |
52
|
|
|
|
53
|
3 |
|
public function saveAll(): void { |
54
|
3 |
|
CacheManager::$cache->store($this->getRootKey('acls'), $this->aclsArray); |
55
|
3 |
|
$classes = [ |
56
|
3 |
|
Role::class, |
57
|
3 |
|
Resource::class, |
58
|
3 |
|
Permission::class |
59
|
3 |
|
]; |
60
|
3 |
|
foreach ($classes as $class) { |
61
|
3 |
|
CacheManager::$cache->store($this->getRootKey($class), $this->parts[$class] ?? []); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function cacheUpdated(): bool { |
66
|
|
|
$old=CacheManager::$cache->fetch($this->getRootKey('acls')); |
67
|
|
|
if ($old!=$this->aclsArray) { |
68
|
|
|
return true; |
69
|
|
|
} |
70
|
|
|
$classes = [ |
71
|
|
|
Role::class, |
72
|
|
|
Resource::class, |
73
|
|
|
Permission::class |
74
|
|
|
]; |
75
|
|
|
foreach ($classes as $class) { |
76
|
|
|
$old=CacheManager::$cache->fetch($this->getRootKey($class)); |
77
|
|
|
if ($old!=($this->parts[$class]??[])) { |
78
|
|
|
return true; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
return false; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function getDetails(): array { |
85
|
|
|
return [ |
86
|
|
|
'lock' => 'In memory or annotations cache' |
87
|
|
|
]; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
|