Passed
Push — main ( 778532...d55b52 )
by Jean-Christophe
02:11
created

AclCacheProvider   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 92.31%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 24
c 1
b 0
f 1
dl 0
loc 48
ccs 24
cts 26
cp 0.9231
rs 10
wmc 9

7 Methods

Rating   Name   Duplication   Size   Complexity  
A saveAll() 0 9 2
A loadAllAcls() 0 3 1
A isAutosave() 0 2 1
A __construct() 0 4 2
A getCacheKeys() 0 6 1
A loadAllPart() 0 3 1
A getDetails() 0 3 1
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 6
	}
29
30 6
	protected function getCacheKeys(): array {
31
		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
		];
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 4
	public function isAutosave(): bool {
50 4
		return false;
51
	}
52
53 4
	public function saveAll(): void {
54 4
		CacheManager::$cache->store($this->getRootKey('acls'), $this->aclsArray);
55
		$classes = [
56 4
			Role::class,
57
			Resource::class,
58
			Permission::class
59
		];
60 4
		foreach ($classes as $class) {
61 4
			CacheManager::$cache->store($this->getRootKey($class), $this->parts[$class]);
62
		}
63 4
	}
64
65
	public function getDetails(): array {
66
		return [
67
			'lock' => 'In memory or annotations cache'
68
		];
69
	}
70
}
71
72