13 class Role implements \Magento\Framework\Acl\LoaderInterface
38 private $aclDataCache;
60 \
Magento\Authorization\Model\Acl\
Role\UserFactory $roleFactory,
62 \
Magento\Framework\Acl\Data\CacheInterface $aclDataCache =
null,
63 Json $serializer =
null,
64 $cacheKey = self::ACL_ROLES_CACHE_KEY
68 $this->_roleFactory = $roleFactory;
70 \
Magento\Framework\Acl\Data\CacheInterface::class
73 $this->cacheKey = $cacheKey;
84 foreach ($this->getRolesArray() as $role) {
85 $parent = $role[
'parent_id'] > 0 ? $role[
'parent_id'] :
null;
86 switch ($role[
'role_type']) {
87 case RoleGroup::ROLE_TYPE:
88 $acl->addRole($this->_groupFactory->create([
'roleId' => $role[
'role_id']]), $parent);
91 case RoleUser::ROLE_TYPE:
92 if (!$acl->hasRole($role[
'role_id'])) {
93 $acl->addRole($this->_roleFactory->create([
'roleId' => $role[
'role_id']]), $parent);
95 $acl->addRoleParent($role[
'role_id'], $parent);
107 private function getRolesArray()
109 $rolesCachedData = $this->aclDataCache->load($this->cacheKey);
110 if ($rolesCachedData) {
111 return $this->serializer->unserialize($rolesCachedData);
114 $roleTableName = $this->_resource->getTableName(
'authorization_role');
118 ->from($roleTableName)
119 ->order(
'tree_level');
122 $this->aclDataCache->save($this->serializer->serialize($rolesArray), $this->cacheKey);
populateAcl(\Magento\Framework\Acl $acl)
__construct(\Magento\Authorization\Model\Acl\Role\GroupFactory $groupFactory, \Magento\Authorization\Model\Acl\Role\UserFactory $roleFactory, \Magento\Framework\App\ResourceConnection $resource, \Magento\Framework\Acl\Data\CacheInterface $aclDataCache=null, Json $serializer=null, $cacheKey=self::ACL_ROLES_CACHE_KEY)
const ACL_ROLES_CACHE_KEY