Phalcon\Acl\Adapter\Database::addRole PHP Метод

addRole() публичный Метод

Example: $acl->addRole(new Phalcon\Acl\Role('administrator'), 'consultor'); $acl->addRole('administrator', 'consultor');
public addRole ( Phalcon\Acl\Role | string $role, string $accessInherits = null ) : boolean
$role Phalcon\Acl\Role | string
$accessInherits string
Результат 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');
        }
        $exists = $this->connection->fetchOne("SELECT COUNT(*) FROM {$this->roles} WHERE name = ?", null, [$role->getName()]);
        if (!$exists[0]) {
            $this->connection->execute("INSERT INTO {$this->roles} VALUES (?, ?)", [$role->getName(), $role->getDescription()]);
            $this->connection->execute("INSERT INTO {$this->accessList} VALUES (?, ?, ?, ?)", [$role->getName(), '*', '*', $this->_defaultAccess]);
        }
        if ($accessInherits) {
            return $this->addInherit($role->getName(), $accessInherits);
        }
        return true;
    }