Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Attributes
Role Class Reference
Inheritance diagram for Role:
LoaderInterface

Public Member Functions

 __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)
 
 populateAcl (\Magento\Framework\Acl $acl)
 
- Public Member Functions inherited from LoaderInterface
 populateAcl (\Magento\Framework\Acl $acl)
 

Data Fields

const ACL_ROLES_CACHE_KEY = 'authorization_role_cached_data'
 

Protected Attributes

 $_resource
 
 $_groupFactory
 
 $_roleFactory
 

Detailed Description

Definition at line 13 of file Role.php.

Constructor & Destructor Documentation

◆ __construct()

__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 
)
Parameters
\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
Json$serializer
string$cacheKey

Definition at line 58 of file Role.php.

65  {
66  $this->_resource = $resource;
67  $this->_groupFactory = $groupFactory;
68  $this->_roleFactory = $roleFactory;
69  $this->aclDataCache = $aclDataCache ?: ObjectManager::getInstance()->get(
70  \Magento\Framework\Acl\Data\CacheInterface::class
71  );
72  $this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class);
73  $this->cacheKey = $cacheKey;
74  }
$resource
Definition: bulk.php:12
$groupFactory

Member Function Documentation

◆ populateAcl()

populateAcl ( \Magento\Framework\Acl  $acl)

Populate ACL with roles from external storage

Parameters
\Magento\Framework\Acl$acl
Returns
void

Definition at line 82 of file Role.php.

83  {
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);
89  break;
90 
91  case RoleUser::ROLE_TYPE:
92  if (!$acl->hasRole($role['role_id'])) {
93  $acl->addRole($this->_roleFactory->create(['roleId' => $role['role_id']]), $parent);
94  } else {
95  $acl->addRoleParent($role['role_id'], $parent);
96  }
97  break;
98  }
99  }
100  }

Field Documentation

◆ $_groupFactory

$_groupFactory
protected

Definition at line 28 of file Role.php.

◆ $_resource

$_resource
protected

Definition at line 23 of file Role.php.

◆ $_roleFactory

$_roleFactory
protected

Definition at line 33 of file Role.php.

◆ ACL_ROLES_CACHE_KEY

const ACL_ROLES_CACHE_KEY = 'authorization_role_cached_data'

Cache key for ACL roles cache

Definition at line 18 of file Role.php.


The documentation for this class was generated from the following file: