X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrush%2Fdrush%2Flib%2FDrush%2FRole%2FRoleBase.php;fp=vendor%2Fdrush%2Fdrush%2Flib%2FDrush%2FRole%2FRoleBase.php;h=5e19d4282ff06be6a2d9e95e4557661de5ce4c28;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/vendor/drush/drush/lib/Drush/Role/RoleBase.php b/vendor/drush/drush/lib/Drush/Role/RoleBase.php new file mode 100644 index 000000000..5e19d4282 --- /dev/null +++ b/vendor/drush/drush/lib/Drush/Role/RoleBase.php @@ -0,0 +1,121 @@ + name pairs. + */ + public $roles; + + /** + * This constructor will allow the role to be selected either + * via the role id or via the role name. + */ + public function __construct($rid = DRUPAL_ANONYMOUS_RID) { + $this->roles = user_roles(); + if (!is_numeric($rid)) { + $role_name = $rid; + if (in_array($role_name, $this->roles)) { + $rid = array_search($role_name, $this->roles); + } + } + + if (isset($this->roles[$rid])) { + $this->rid = $rid; + // In D8+ Role is an object. + $this->name = is_object($this->roles[$rid]) ? $this->roles[$rid]->label() : $this->roles[$rid]; + } + else { + throw new RoleException(dt('Could not find the role: !role', array('!role' => $rid))); + } + } + + /* + * Get all perms for a given Role. + */ + public function getPerms() { + return array(); + } + + /* + * Get all perms for a given module. + */ + public function getModulePerms($module) { + return array(); + } + + /* + * Get all permissions site-wide. + */ + public function getAllModulePerms() { + $permissions = array(); + drush_include_engine('drupal', 'environment'); + $module_list = drush_module_list(); + ksort($module_list); + foreach ($module_list as $module) { + if ($perms = $this->getModulePerms($module)) { + $permissions = array_merge($permissions, $perms); + } + } + return $permissions; + } + + public function role_create($role_machine_name, $role_human_readable_name = '') { + } + + public function delete() { + } + + public function add($perm) { + $perms = $this->getPerms(); + if (!in_array($perm, $perms)) { + $this->grant_permissions(array($perm)); + return TRUE; + } + else { + drush_log(dt('"!role" already has the permission "!perm"', array( + '!perm' => $perm, + '!role' => $this->name, + )), 'ok'); + return FALSE; + } + } + + public function remove($perm) { + $perms = $this->getPerms(); + if (in_array($perm, $perms)) { + $this->revoke_permissions(array($perm)); + return TRUE; + } + else { + drush_log(dt('"!role" does not have the permission "!perm"', array( + '!perm' => $perm, + '!role' => $this->name, + )), 'ok'); + return FALSE; + } + } + + public function grant_permissions($perms) { + } + + public function revoke_permissions($perms) { + } +}