ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Access.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26
31class Access
32{
33 private \ilRbacSystem $rbac_system;
34 private ?int $ref_id = null;
35
36 private bool $access_checked = false;
37
41 public function __construct(
42 RBACServices $rbac,
45 ) {
46 $this->rbac_system = $rbac->system();
47 $this->ref_id = $http->wrapper()->query()->has('ref_id')
48 ? $http->wrapper()->query()->retrieve('ref_id', $refinery->kindlyTo()->int())
49 : null;
50 }
51
52 public function checkAccessAndThrowException(string $permission): void
53 {
54 if (!$this->hasUserPermissionTo($permission)) {
55 throw new \ilException('Permission denied');
56 }
57 }
58
59 public function hasUserPermissionTo(string $permission): bool
60 {
61 if ($this->ref_id === null) {
62 return false;
63 }
64 // split permission string
65 $permissions = explode(',', $permission);
66 foreach ($permissions as $p) {
67 if ($this->rbac_system->checkAccess($p, $this->ref_id)) {
68 $this->access_checked = true;
69 return true;
70 }
71 }
72 $this->access_checked = true;
73 return false;
74 }
75
76 public function __destruct()
77 {
78 if (!$this->access_checked) {
79 // throw new \RuntimeException('No Access Check');
80 }
81 }
82
83 public function requireReadable(): void
84 {
85 $this->require('read');
86 }
87
88 public function requireWritable(): void
89 {
90 $this->require('write');
91 }
92
93 public function require(string $permissions): void
94 {
95 $this->checkAccessAndThrowException($permissions);
96 }
97
98}
Provides fluid interface to RBAC services.
system()
Get the interface to the RBAC system.
Builds data types.
Definition: Factory.php:36
checkAccessAndThrowException(string $permission)
Definition: Access.php:52
__construct(RBACServices $rbac, Services $http, Factory $refinery,)
ilObjMainMenuAccess constructor.
Definition: Access.php:41
hasUserPermissionTo(string $permission)
Definition: Access.php:59
Class Services.
Definition: Services.php:38
$http
Definition: deliver.php:30