Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
AclArrayProvider.php
Go to the documentation of this file.
1<?php
3
10
19abstract class AclArrayProvider implements AclProviderInterface {
20
21 protected $aclsArray;
22
23 protected $parts;
24
25 public function __construct() {}
26
27 protected function loadAllPart($class): array {
28 $elements = [];
29 $part = $this->parts[$class] ?? [];
30 foreach ($part as $partArray) {
31 $elm = new $class();
32 $elm->fromArray($partArray);
33 $elements[$partArray['name']] = $elm;
34 }
35 return $elements;
36 }
37
43 public function loadAllAcls(): array {
44 $acls = [];
45 foreach ($this->aclsArray as $aclArray) {
46 $aclElement = new AclElement();
47 $aclElement->fromArray($aclArray);
48 $acls[$aclElement->getId_()] = $aclElement;
49 }
50 return $acls;
51 }
52
53 public function saveAcl(AclElement $aclElement) {
54 $this->aclsArray[$aclElement->getId_()] = $aclElement->toArray();
55 }
56
57 public function removeAcl(AclElement $aclElement) {
58 unset($this->aclsArray[$aclElement->getId_()]);
59 }
60
66 public function loadAllPermissions(): array {
67 return $this->loadAllPart(Permission::class);
68 }
69
75 public function loadAllResources(): array {
76 return $this->loadAllPart(Resource::class);
77 }
78
84 public function loadAllRoles(): array {
85 return $this->loadAllPart(Role::class);
86 }
87
88 public function savePart(\Ubiquity\security\acl\models\AbstractAclPart $part) {
89 $class = \get_class($part);
90 $this->parts[$class][$part->getName()] = $part->toArray();
91 }
92
93 public function updatePart(string $id,\Ubiquity\security\acl\models\AbstractAclPart $part) {
94 $class = \get_class($part);
95 $this->parts[$class][$id] = $part->toArray();
96 }
97
98 public function removePart(\Ubiquity\security\acl\models\AbstractAclPart $part) {
99 $name = $part->getName();
100 if ($part instanceof Resource) {
101 $field = 'resource';
102 } elseif ($part instanceof Role) {
103 $field = 'role';
104 } else {
105 $field = 'permission';
106 }
107 foreach ($this->aclsArray as $acl) {
108 if ($acl[$field]['name'] === $name) {
109 throw new AclException("$name is in use in ACLs and can't be removed!");
110 }
111 }
112 unset($this->parts[\get_class($part)][$name]);
113 }
114
115 public function existPart(AbstractAclPart $part): bool {
116 $name = $part->getName();
117 return isset($this->parts[\get_class($part)][$name]);
118 }
119
120 public function existAcl(AclElement $aclElement): bool {
121 return isset($this->aclsArray[$aclElement->getId_()]);
122 }
123
124 public function getModelClassesSwap(): array {
125 return [];
126 }
127
133 public function clearAll(): void {
134 $this->parts = [];
135 $this->aclsArray = [];
136 }
137}
138
Ubiquity\exceptions$AclException This class is part of Ubiquity.
Ubiquity\security\acl\models$AbastractAclElement This class is part of Ubiquity.
Ubiquity\security\acl\models$AclElement This class is part of Ubiquity.
Ubiquity\security\acl\models$Permission This class is part of Ubiquity.
Ubiquity\security\acl\models$Resource This class is part of Ubiquity.
Definition Resource.php:12
Ubiquity\security\acl\models$Role This class is part of Ubiquity.
Definition Role.php:12
Ubiquity\security\acl\persistence$AclArrayProvider This class is part of Ubiquity.
removePart(\Ubiquity\security\acl\models\AbstractAclPart $part)
updatePart(string $id,\Ubiquity\security\acl\models\AbstractAclPart $part)
savePart(\Ubiquity\security\acl\models\AbstractAclPart $part)
Ubiquity\security\acl\persistence$AclProviderInterface This class is part of Ubiquity.
Class Configuration \config.