Phalcon\Acl\Adapter\Mongo::addRole PHP Method

addRole() public method

Example: $acl->addRole(new Phalcon\Acl\Role('administrator'), 'consultor'); $acl->addRole('administrator', 'consultor');
public addRole ( string $role, array $accessInherits = null ) : boolean
$role string
$accessInherits array
return boolean
    public function addRole($role, $accessInherits = null)
    {
        if (is_string($role)) {
            $role = new Role($role, ucwords($role) . ' Role');
        }
        if (!$role instanceof RoleInterface) {
            throw new Exception('Role must be either an string or implement RoleInterface');
        }
        $roles = $this->getCollection('roles');
        $exists = $roles->count(['name' => $role->getName()]);
        if (!$exists) {
            $roles->insert(['name' => $role->getName(), 'description' => $role->getDescription()]);
            $this->getCollection('accessList')->insert(['roles_name' => $role->getName(), 'resources_name' => '*', 'access_name' => '*', 'allowed' => $this->_defaultAccess]);
        }
        if ($accessInherits) {
            return $this->addInherit($role->getName(), $accessInherits);
        }
        return true;
    }