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

PermissionsMap::load()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
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