Passed
Push — main ( 280cf4...2747d9 )
by Jean-Christophe
02:02
created

AclArrayProvider::loadAllAcls()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 0
dl 0
loc 8
ccs 7
cts 7
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Ubiquity\security\acl\persistence;
3
4
use Ubiquity\security\acl\models\AclElement;
5
use Ubiquity\security\acl\models\Permission;
6
use Ubiquity\security\acl\models\Resource;
7
use Ubiquity\security\acl\models\Role;
8
9
/**
10
 * Ubiquity\security\acl\persistence$AclArrayProvider
11
 * This class is part of Ubiquity
12
 *
13
 * @author jc
14
 * @version 1.0.0
15
 *
16
 */
17
abstract class AclArrayProvider implements AclProviderInterface {
18
19
	protected $aclsArray;
20
21
	protected $parts;
22
23
	public function __construct() {}
24
25 3
	protected function loadAllPart($class): array {
26 3
		$elements = [];
27 3
		foreach ($this->parts[$class] as $partArray) {
28 3
			$elm = new $class();
29 3
			$elm->fromArray($partArray);
30 3
			$elements[$partArray['name']] = $elm;
31
		}
32 3
		return $elements;
33
	}
34
35
	/**
36
	 *
37
	 * {@inheritdoc}
38
	 * @see \Ubiquity\security\acl\persistence\AclProviderInterface::loadAllAcls()
39
	 */
40 3
	public function loadAllAcls(): array {
41 3
		$acls = [];
42 3
		foreach ($this->aclsArray as $aclArray) {
43 3
			$aclElement = new AclElement();
44 3
			$aclElement->fromArray($aclArray);
45 3
			$acls[$aclElement->getId_()] = $aclElement;
46
		}
47 3
		return $acls;
48
	}
49
50 1
	protected function _saveAcl(AclElement $aclElement) {
51 1
		$this->aclsArray[$aclElement->getId_()] = $aclElement->toArray();
52 1
	}
53
54
	/**
55
	 *
56
	 * {@inheritdoc}
57
	 * @see \Ubiquity\security\acl\persistence\AclProviderInterface::loadAllPermissions()
58
	 */
59 3
	public function loadAllPermissions(): array {
60 3
		return $this->loadAllPart(Permission::class);
61
	}
62
63
	/**
64
	 *
65
	 * {@inheritdoc}
66
	 * @see \Ubiquity\security\acl\persistence\AclProviderInterface::loadAllResources()
67
	 */
68 3
	public function loadAllResources(): array {
69 3
		return $this->loadAllPart(Resource::class);
70
	}
71
72
	/**
73
	 *
74
	 * {@inheritdoc}
75
	 * @see \Ubiquity\security\acl\persistence\AclProviderInterface::loadAllRoles()
76
	 */
77 3
	public function loadAllRoles(): array {
78 3
		return $this->loadAllPart(Role::class);
79
	}
80
81 2
	protected function _savePart(\Ubiquity\security\acl\models\AbstractAclPart $part) {
82 2
		$class = \get_class($part);
83 2
		$this->parts[$class][$part->getName()] = $part->toArray();
84 2
	}
85
}
86
87