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;
}