1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
baseaccesscontroller.php
См. документацию.
1<?php
8
9namespace Bitrix\Main\Access;
10
11use Bitrix\Main\Access\Event\Event;
12use Bitrix\Main\Access\Event\EventDictionary;
13use Bitrix\Main\Access\Exception\UnknownActionException;
14use Bitrix\Main\Access\Filter\Factory\FilterControllerFactory;
15use Bitrix\Main\Access\Filter\FilterFactory;
16use Bitrix\Main\Access\Rule\Factory\RuleControllerFactory;
17use Bitrix\Main\Access\Rule\RuleFactory;
18use Bitrix\Main\Access\User\AccessibleUser;
19
21 implements AccessibleController
22{
26 protected const RULE_SUFFIX = 'Rule';
27
28 protected static $register = [];
29
30 /* @var AccessibleUser $user */
31 protected $user;
32
34
36
37 public static function getInstance($userId): static
38 {
39 if (!isset(static::$register[static::class][$userId]))
40 {
41 static::$register[static::class][$userId] = new static($userId);
42 }
43 return static::$register[static::class][$userId];
44 }
45
46 public static function can($userId, string $action, $itemId = null, $params = null): bool
47 {
48 $userId = (int) $userId;
49 $itemId = (int) $itemId;
50
51 $controller = static::getInstance($userId);
52 return $controller->checkByItemId($action, $itemId, $params);
53 }
54
55 public function __construct(int $userId)
56 {
57 $this->user = $this->loadUser($userId);
58 $this->ruleFactory = new RuleControllerFactory();
59 $this->filterFactory = new FilterControllerFactory();
60 }
61
62 public function getUser(): AccessibleUser
63 {
64 return $this->user;
65 }
66
67 public function checkByItemId(string $action, int $itemId = null, $params = null): bool
68 {
69 $item = $this->loadItem($itemId);
70 return $this->check($action, $item, $params);
71 }
72
73 public function check(string $action, AccessibleItem $item = null, $params = null): bool
74 {
75 $rule = $this->ruleFactory->createFromAction($action, $this);
76 if (!$rule)
77 {
79 }
80
82 $isAccess = $event->isAccess();
83
84 if (!is_null($isAccess))
85 {
86 return $isAccess;
87 }
88
89 $isAccess = $rule->execute($item, $params);
90
92
93 $isAccess = $event->isAccess() ?? $isAccess;
94
95 return $isAccess;
96 }
97
111 {
112 $result = [];
113 foreach ($request as $actionId => $params)
114 {
115 $result[$actionId] = $this->check($actionId, $item, $params);
116 }
117 return $result;
118 }
119
120 abstract protected function loadItem(int $itemId = null): ?AccessibleItem;
121
122 abstract protected function loadUser(int $userId): AccessibleUser;
123
127 protected function getRuleName(string $action): ?string
128 {
129 $action = explode('_', $action);
130 $action = array_map(function($el) {
131 return ucfirst(strtolower($el));
132 }, $action);
133 return $this->getRuleNamespace() . implode($action) . static::RULE_SUFFIX;
134 }
135
139 protected function getRuleNamespace(): string
140 {
141 $class = new \ReflectionClass($this);
142 $namespace = $class->getNamespaceName();
143 return $namespace.'\\'.static::RULE_SUFFIX.'\\';
144 }
145
146 protected function sendEvent(string $eventName, string $action, AccessibleItem $item = null, $params = null, bool $isAccess = null)
147 {
148 $event = new Event(
149 static::class,
150 $eventName,
151 [
152 'user' => $this->user,
153 'item' => $item,
154 'action' => $action,
155 'params' => $params,
156 'isAccess' => $isAccess
157 ]
158 );
159 $event->send();
160
161 return $event;
162 }
163
167 public function getEntityFilter(string $action, string $entityName, $params = null): ?array
168 {
169 $filter = $this->filterFactory->createFromAction($action, $this);
170 if (!$filter)
171 {
172 return null;
173 }
174
175 $params = (array)($params ?? []);
176 $params['action'] = $action;
177
178 return $filter->getFilter($entityName, $params);
179 }
180}
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
getEntityFilter(string $action, string $entityName, $params=null)
Определения baseaccesscontroller.php:167
batchCheck(array $request, AccessibleItem $item)
Определения baseaccesscontroller.php:110
static can($userId, string $action, $itemId=null, $params=null)
Определения baseaccesscontroller.php:46
checkByItemId(string $action, int $itemId=null, $params=null)
Определения baseaccesscontroller.php:67
sendEvent(string $eventName, string $action, AccessibleItem $item=null, $params=null, bool $isAccess=null)
Определения baseaccesscontroller.php:146
check(string $action, AccessibleItem $item=null, $params=null)
Определения baseaccesscontroller.php:73
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$filter
Определения iblock_catalog_list.php:54
$event
Определения prolog_after.php:141
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$action
Определения file_dialog.php:21