Passed
Push — main ( 5080f0...5604a8 )
by Jean-Christophe
02:26
created

PermissionsMap   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 46
ccs 20
cts 20
cp 1
rs 10
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A getKey() 0 2 1
A addAction() 0 4 1
A save() 0 2 1
A init() 0 2 1
A load() 0 2 1
A getRessourcePermission() 0 2 1
1
<?php
2
namespace Ubiquity\security\acl\cache;
3
4
use Ubiquity\cache\CacheManager;
5
use Ubiquity\security\acl\cache\traits\AclCacheTrait;
6
7
/**
8
 * Ubiquity\security\acl\cache$PermissionsMap
9
 * This class is part of Ubiquity
10
 *
11
 * @author jc
12
 * @version 1.0.0
13
 *
14
 */
15
class PermissionsMap {
16
	use AclCacheTrait;
17
18
	/**
19
	 *
20
	 * @var array
21
	 */
22
	private $arrayMap;
23
24
	private const CACHE_KEY = 'permissionsMap';
25
26 2
	public function __construct() {
27 2
		$this->createCache($this->getRootKey(self::CACHE_KEY));
28 2
	}
29
30 2
	protected function getKey($controller, $action) {
31 2
		return \crc32($controller . $action) . '_';
32
	}
33
34 2
	public function addAction(string $controller, string $action, ?string $resource = '*', ?string $permission = 'ALL') {
35 2
		$this->arrayMap[$this->getKey($controller, $action)] = [
36 2
			'resource' => $resource,
37 2
			'permission' => $permission
38
		];
39 2
	}
40
41
	/**
42
	 *
43
	 * @param string $controller
44
	 * @param string $action
45
	 * @return array|NULL
46
	 */
47 1
	public function getRessourcePermission(string $controller, string $action) {
48 1
		return $this->arrayMap[$this->getKey($controller, $action)] ?? null;
49
	}
50
51 2
	public function save() {
52 2
		CacheManager::$cache->store($this->getRootKey(self::CACHE_KEY), $this->arrayMap);
53 2
	}
54
55 2
	public function init() {
56 2
		CacheManager::$cache->store($this->getRootKey(self::CACHE_KEY), $this->arrayMap = []);
57 2
	}
58
59 1
	public function load() {
60 1
		$this->arrayMap = CacheManager::$cache->fetch($this->getRootKey(self::CACHE_KEY));
61 1
	}
62
}
63
64