Passed
Push — main ( f54f2d...d212fa )
by Jean-Christophe
02:04
created

AclArrayProvider::_savePart()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
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 1
	protected function loadAllPart($class): array {
26 1
		$elements = [];
27 1
		foreach ($this->parts[$class] as $partArray) {
28
			$elm = new $class();
29
			$elm->fromArray($partArray);
30
			$elements[$partArray['name']] = $elm;
31
		}
32 1
		return $elements;
33
	}
34
35
	/**
36
	 *
37
	 * {@inheritdoc}
38
	 * @see \Ubiquity\security\acl\persistence\AclProviderInterface::loadAllAcls()
39
	 */
40 1
	public function loadAllAcls(): array {
41 1
		$acls = [];
42 1
		foreach ($this->aclsArray as $aclArray) {
43 1
			$aclElement = new AclElement();
44 1
			$aclElement->fromArray($aclArray);
45 1
			$acls[$aclElement->getId_()] = $aclElement;
46
		}
47 1
		return $acls;
48
	}
49
50
	protected function _saveAcl(AclElement $aclElement) {
51
		$this->aclsArray[$aclElement->getId_()] = $aclElement->toArray();
52
	}
53
54
	/**
55
	 *
56
	 * {@inheritdoc}
57
	 * @see \Ubiquity\security\acl\persistence\AclProviderInterface::loadAllPermissions()
58
	 */
59 1
	public function loadAllPermissions(): array {
60 1
		return $this->loadAllPart(Permission::class);
61
	}
62
63
	/**
64
	 *
65
	 * {@inheritdoc}
66
	 * @see \Ubiquity\security\acl\persistence\AclProviderInterface::loadAllResources()
67
	 */
68 1
	public function loadAllResources(): array {
69 1
		return $this->loadAllPart(Resource::class);
70
	}
71
72
	/**
73
	 *
74
	 * {@inheritdoc}
75
	 * @see \Ubiquity\security\acl\persistence\AclProviderInterface::loadAllRoles()
76
	 */
77 1
	public function loadAllRoles(): array {
78 1
		return $this->loadAllPart(Role::class);
79
	}
80
81
	protected function _savePart(\Ubiquity\security\acl\models\AbstractAclPart $part) {
82
		$class = \get_class($part);
83
		$this->parts[$class][$part->getName()] = $part->toArray();
84
	}
85
}
86
87