Test Failed
Push — main ( 573841...5a0b4f )
by Jean-Christophe
06:17
created

PermissionsMap   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 36
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A save() 0 2 1
A getKey() 0 2 1
A addAction() 0 4 1
A load() 0 2 1
A init() 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
	public function __construct() {
27
		$this->createCache(self::CACHE_KEY);
28
	}
29
30
	protected function getKey($controller, $action) {
31
		return \crc32($controller . $action) . '_';
32
	}
33
34
	public function addAction(string $controller, string $action, string $resource, ?string $permission = '*') {
35
		$this->arrayMap[$this->getKey($controller, $action)] = [
36
			'resource' => $resource,
37
			'permission' => $permission
38
		];
39
	}
40
41
	public function save() {
42
		CacheManager::$cache->store($this->getRootKey(self::CACHE_KEY), $this->arrayMap);
43
	}
44
45
	public function init() {
46
		CacheManager::$cache->store($this->getRootKey(self::CACHE_KEY), $this->arrayMap = []);
47
	}
48
49
	public function load() {
50
		$this->arrayMap = CacheManager::$cache->fetch($this->getRootKey(self::CACHE_KEY));
51
	}
52
}
53
54