Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ResourceLoader.php
Go to the documentation of this file.
1 <?php
9 
14 
15 class ResourceLoader implements \Magento\Framework\Acl\LoaderInterface
16 {
22  protected $_resourceProvider;
23 
29  protected $_resourceFactory;
30 
35  public function __construct(ProviderInterface $resourceProvider, AclResourceFactory $resourceFactory)
36  {
37  $this->_resourceProvider = $resourceProvider;
38  $this->_resourceFactory = $resourceFactory;
39  }
40 
48  public function populateAcl(Acl $acl)
49  {
50  $this->_addResourceTree($acl, $this->_resourceProvider->getAclResources(), null);
51  }
52 
63  protected function _addResourceTree(Acl $acl, array $resources, AclResource $parent = null)
64  {
65  foreach ($resources as $resourceConfig) {
66  if (!isset($resourceConfig['id'])) {
67  throw new \InvalidArgumentException('Missing ACL resource identifier');
68  }
70  $resource = $this->_resourceFactory->createResource(['resourceId' => $resourceConfig['id']]);
71  $acl->addResource($resource, $parent);
72  if (isset($resourceConfig['children'])) {
73  $this->_addResourceTree($acl, $resourceConfig['children'], $resource);
74  }
75  }
76  }
77 }
__construct(ProviderInterface $resourceProvider, AclResourceFactory $resourceFactory)
$resource
Definition: bulk.php:12
addResource($resource, $parent=null)
Definition: Acl.php:283