/
v.bolshakov
/
AIEcosystem-Testing
Обзор
Документация
Войти
/
v.bolshakov
/
AIEcosystem-Testing
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
dev
common/components/CheckAccess.php
69 строк
2 KB
Developer
Initial commit
03 авг 2026, 17:43
03 авг 2026, 17:43
7433917
Код
Авторство
О чём код?
<?php namespace common\components; use common\helpers\DateHelper; use common\models\Acl; use common\models\AclRoleRule; use common\models\AclRule; use yii\base\Component; use yii\base\InvalidConfigException; use yii\rbac\CheckAccessInterface; /** * Компонент для проверки наличия правила у пользователя * * @author Dmitry E. Semenov <sde.tomsk@gmail.com> * @copyright Self (c) 2020 */ class CheckAccess extends Component implements CheckAccessInterface { /** * Проверить доступ пользователя к текущему правилу * * @param int|string $user_id - пользователь * @param string $permissionName - правило * @param array $params - дополнительные параметры * @return bool * @throws InvalidConfigException */ public function checkAccess($user_id, $permissionName, $params = []) { $rules = $this->getAssignments($user_id); return in_array($permissionName, $rules) or in_array('full_access', $rules); } /** * Получить правила по личности * * @param $user_id * @return mixed * @throws InvalidConfigException */ public function getAssignments($user_id) { static $store = null; if (!isset($store[$user_id])) { $a = AclRule::getAlias(); $data = AclRule::find() ->distinct() ->select('code') ->alias($a) ->innerJoin(['arr' => AclRoleRule::tableName()], $a . '.id = arr.rule_id') ->innerJoin(['a' => Acl::tableName()], 'a.role_id = arr.role_id') ->andWhere([ 'a.user_id' => $user_id ]) ->asArray() // ->cache(DateHelper::MINUTE) ->column(); $store[$user_id] = $data; } return $store[$user_id]; } }