/** * Fill relations between roles and permissions */ protected function fillChildren() { foreach ($this->getConfig('children') as $roleName => $permissionsNames) { $role = $this->authManager->getRole($roleName); foreach ($permissionsNames as $permissionName) { $permission = $this->authManager->getPermission($permissionName); if (!$this->authManager->hasChild($role, $permission)) { $this->authManager->addChild($role, $permission); } } } }
/** * Adding or deleting items if needed */ protected function manageItems() { foreach ($this->_items as $item) { if ($item instanceof Rule) { $item_exist = $this->_auth->getRule($item->name); } elseif ($item instanceof Role) { $item_exist = $this->_auth->getRole($item->name); } elseif ($item instanceof Permission) { $item_exist = $this->_auth->getPermission($item->name); } else { throw new InvalidParamException('Adding unsupported object type.'); } if ($item_exist) { if ($item_exist instanceof __PHP_Incomplete_Class) { $need_update = true; } else { if ($item_exist instanceof Rule) { $item->updatedAt = $item_exist->updatedAt; $need_update = serialize($item_exist) != serialize($item); } else { $need_update = $item_exist->description != $item->description || $item_exist->ruleName != $item->ruleName || $item_exist->data != $item->data; } } if ($need_update) { Console::stdout("Updating {$item->name} item data.\n"); $this->_auth->update($item->name, $item); } } else { Console::stdout("New item added: {$item->name}\n"); $this->_auth->add($item); } } /** @var Role|Permission|Rule $items */ $items = ArrayHelper::merge($this->_auth->getRules(), $this->_auth->getRules(), $this->_auth->getPermissions()); foreach ($items as $existing_item) { if (!isset($this->_items[$existing_item->name])) { Console::stdout(Console::ansiFormat('Item removed: ' . $existing_item->name . "\n", [Console::FG_RED])); $this->_auth->remove($existing_item); } } }