Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
WebapiRoleLocator.php
Go to the documentation of this file.
1 <?php
7 namespace Magento\Webapi\Model;
8 
9 use Magento\Authorization\Model\ResourceModel\Role\CollectionFactory as RoleCollectionFactory;
13 
15 {
19  protected $userContext;
20 
25 
32  public function __construct(
34  RoleCollectionFactory $roleCollectionFactory
35  ) {
36  $this->userContext = $userContext;
37  $this->roleCollectionFactory = $roleCollectionFactory;
38  }
39 
43  public function getAclRoleId()
44  {
45  $userId = $this->userContext->getUserId();
46  $userType = $this->userContext->getUserType();
47 
48  $roleCollection = $this->roleCollectionFactory->create();
50  $role = $roleCollection->setUserFilter($userId, $userType)->getFirstItem();
51 
52  if (!$role->getId()) {
53  return null;
54  }
55 
56  return $role->getId();
57  }
58 }
__construct(UserContextInterface $userContext, RoleCollectionFactory $roleCollectionFactory)