Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
accesscontroller.php
1
<?php
9
namespace
Bitrix\Sender\Access
;
10
11
use
Bitrix\Main\Access\AccessibleItem
;
12
use
Bitrix\Main\Access\BaseAccessController
;
13
use
Bitrix\Main\Access\Event\EventDictionary
;
14
use
Bitrix\Main\Access\User\AccessibleUser
;
15
use
Bitrix\Sender\Access\Exception\UnknownActionException
;
16
use
Bitrix\Sender\Access\Model\UserModel
;
17
18
class
AccessController
extends
BaseAccessController
19
{
20
private
const
BASE_RULE =
'Base'
;
21
31
public
function
check
(
string
$action,
AccessibleItem
$item =
null
, $params =
null
): bool
32
{
33
$ruleName = $this->
getRuleName
($action);
34
35
if
(!$ruleName || !class_exists($ruleName))
36
{
37
throw
new
UnknownActionException
($action);
38
}
39
40
$event = $this->
sendEvent
(EventDictionary::EVENT_ON_BEFORE_CHECK, $action,
null
, $params);
41
$isAccess = $event->isAccess();
42
43
if
(!is_null($isAccess))
44
{
45
return
$isAccess;
46
}
47
48
$params[
'action'
] = $action;
49
$isAccess = (
new
$ruleName($this))->execute(
null
, $params);
50
51
if
($isAccess)
52
{
53
return
$isAccess;
54
}
55
56
$event = $this->
sendEvent
(EventDictionary::EVENT_ON_AFTER_CHECK, $action,
null
, $params, $isAccess);
57
58
$isAccess = $event->isAccess() ?? $isAccess;
59
60
return
$isAccess;
61
}
62
63
public
function
isAdmin
()
64
{
65
return
$this->user->isAdmin();
66
}
67
68
protected
function
getRuleName
(
string
$actionCode): ?string
69
{
70
$actionName =
ActionDictionary::getActionName
($actionCode);
71
if
(!$actionName)
72
{
73
return
null
;
74
}
75
76
$action = explode(
'_'
, $actionName);
77
$action = array_map(
78
function
($el)
79
{
80
return
ucfirst(mb_strtolower($el));
81
}, $action
82
);
83
84
$ruleClass = $this->
getRuleNamespace
() .implode($action).self::RULE_SUFFIX;
85
86
87
if
(class_exists($ruleClass))
88
{
89
return
$ruleClass;
90
}
91
92
return
$this->
getRuleNamespace
().self::BASE_RULE.self::RULE_SUFFIX;
93
}
94
95
protected
function
loadItem
(
int
$itemId =
null
): ?
AccessibleItem
96
{
97
return
null
;
98
}
99
100
protected
function
loadUser
(
int
$userId):
AccessibleUser
101
{
102
return
UserModel::createFromId
($userId);
103
}
104
}
Bitrix\Main\Access\BaseAccessController
Definition
baseaccesscontroller.php:23
Bitrix\Main\Access\BaseAccessController\sendEvent
sendEvent(string $eventName, string $action, AccessibleItem $item=null, $params=null, bool $isAccess=null)
Definition
baseaccesscontroller.php:147
Bitrix\Main\Access\BaseAccessController\getRuleNamespace
getRuleNamespace()
Definition
baseaccesscontroller.php:140
Bitrix\Main\Access\Event\EventDictionary
Definition
eventdictionary.php:13
Bitrix\Sender\Access\AccessController
Definition
accesscontroller.php:19
Bitrix\Sender\Access\AccessController\loadItem
loadItem(int $itemId=null)
Definition
accesscontroller.php:95
Bitrix\Sender\Access\AccessController\getRuleName
getRuleName(string $actionCode)
Definition
accesscontroller.php:68
Bitrix\Sender\Access\AccessController\isAdmin
isAdmin()
Definition
accesscontroller.php:63
Bitrix\Sender\Access\AccessController\check
check(string $action, AccessibleItem $item=null, $params=null)
Definition
accesscontroller.php:31
Bitrix\Sender\Access\AccessController\loadUser
loadUser(int $userId)
Definition
accesscontroller.php:100
Bitrix\Sender\Access\ActionDictionary\getActionName
static getActionName(string $value)
Definition
actiondictionary.php:174
Bitrix\Sender\Access\Exception\UnknownActionException
Definition
unknownactionexception.php:14
Bitrix\Sender\Access\Model\UserModel
Definition
usermodel.php:16
Bitrix\Main\Access\AccessibleItem
Definition
accessibleitem.php:13
Bitrix\Main\Access\User\AccessibleUser
Definition
accessibleuser.php:13
Bitrix\Main\Access\User\AccessibleUser\createFromId
static createFromId(int $userId)
Bitrix\Sender\Access
Definition
accesscontroller.php:9
modules
sender
lib
access
accesscontroller.php
Создано системой
1.10.0