Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
AclElement.php
Go to the documentation of this file.
1<?php
2
4
6
17
23 #[\Ubiquity\attributes\items\Id()]
24 #[\Ubiquity\attributes\items\Column(name:'id',nullable:false,dbType:'int(11)')]
25 protected $id;
26
33 #[\Ubiquity\attributes\items\ManyToOne()]
34 #[\Ubiquity\attributes\items\JoinColumn(className:"Ubiquity\\security\\acl\\models\\Role",name: "roleName", nullable: false)]
35 protected $role;
36
43 #[\Ubiquity\attributes\items\ManyToOne()]
44 #[\Ubiquity\attributes\items\JoinColumn(className:"Ubiquity\\security\\acl\\models\\Permission",name: "permissionName", nullable: false)]
45 protected $permission;
46
53 #[\Ubiquity\attributes\items\ManyToOne()]
54 #[\Ubiquity\attributes\items\JoinColumn(className:"Ubiquity\\security\\acl\\models\\Resource",name: "resourceName", nullable: false)]
55 protected $resource;
56
61 #[Transient]
62 protected $type='';
63
69 public function getRole() {
70 return $this->role;
71 }
72
77 public function getPermission() {
78 return $this->permission;
79 }
80
85 public function getResource() {
86 return $this->resource;
87 }
88
89 public function fromArray($aclArray) {
90 $role = new Role();
91 $role->fromArray($aclArray['role']);
92 $resource = new Resource();
93 $resource->fromArray($aclArray['resource']);
94 $permission = new Permission();
95 $permission->fromArray($aclArray['permission']);
96 $this->role = $role;
97 $this->permission = $permission;
98 $this->resource = $resource;
99 }
100
101 public function toArray(): array {
102 return [
103 'resource' => $this->resource->toArray(),
104 'role' => $this->role->toArray(),
105 'permission' => $this->permission->toArray()
106 ];
107 }
108
109 public function allow(Role $role, Resource $resource, Permission $permission) {
110 $this->role = $role;
111 $this->resource = $resource;
112 $this->permission = $permission;
113 }
114
119 public function getId() {
120 return $this->id;
121 }
122
127 public function setId($id) {
128 $this->id = $id;
129 }
130
135 public function setRole($role) {
136 $this->role = $role;
137 }
138
143 public function setPermission($permission) {
144 $this->permission = $permission;
145 }
146
151 public function setResource($resource) {
152 $this->resource = $resource;
153 }
154
158 public function getType(): string {
159 return $this->type;
160 }
161
165 public function setType(?string $type): void {
166 $this->type = $type;
167 }
168
169 public function getId_() {
170 $id = '';
171 if (isset($this->role)) {
172 $id = $this->role->getName();
173 }
174 if (isset($this->resource)) {
175 $id .= $this->resource->getName();
176 }
177 if (isset($this->permission)) {
178 $id .= $this->permission->getName();
179 }
180 return \crc32($id) . '.';
181 }
182
183 public function castAs(string $class) {
184 return unserialize(sprintf('O:%d:"%s"%s', \strlen($class), $class, \strstr(\strstr(\serialize($this), '"'), ':')));
185 }
186}
187
Ubiquity\security\acl\models$AclElement This class is part of Ubiquity.
allow(Role $role, Resource $resource, Permission $permission)
$id
@id @column("name"=>"id","nullable"=>false,"dbType"=>"int(11)")
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