/** * Here we read rules from DB and put them into a form that BjyAuthorize's Controller.php understands */ public function getRules() { $rules = array(); // initialize the rules array // // get the doctrine shemaManager $schemaManager = $this->objectManager->getConnection()->getSchemaManager(); // check if the roles table exists, if it does not, do not bother querying if ($schemaManager->tablesExist(array('roles')) === true) { //read from object store a set of (role, controller, action) $result = $this->objectRepository->findAll(); // if a result set exists if (count($result)) { //transform to object BjyAuthorize will understand foreach ($result as $key => $role) { $roleId = $role->getRoleId(); // check if any resource access has been defined before // if it has, continue with normal operations // else, allow access to this first user if (!$role->getResources()) { continue; } foreach ($role->getResources() as $rle) { $this->defaultRules['allow'][] = [[$roleId], $rle->getControllerId(), []]; } } } } return $this->defaultRules; }
/** * Here we read rules from DB and put them into a form that BjyAuthorize's Controller.php understands * @return \Zend\Permissions\Acl\Resource\ResourceInterface[] */ public function getResources() { $resources = []; // get the doctrine shemaManager $schemaManager = $this->objectManager->getConnection()->getSchemaManager(); // check if the roles table exists, if it does not, do not bother querying if ($schemaManager->tablesExist(['admin_rule']) === true) { //read from object store a set of (controller) $result = $this->service->fetchAllResources([], [], ['controller_id']); // if a result set exists if (count($result)) { //transform to object BjyAuthorize will understand foreach ($result as $resource) { $resources[$resource->getControllerId()] = []; } } } return $resources; }