Skip to content

Commit

Permalink
Merge pull request #4 from CottaCush/updates/implement-psr2
Browse files Browse the repository at this point in the history
(Cleanup): Apply PSR coding convention
  • Loading branch information
Olawale Lawal authored Aug 28, 2019
2 parents 3ee49f6 + 104d3c9 commit d1b6e1d
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 32 deletions.
24 changes: 20 additions & 4 deletions migrations/m151005_151946_install.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/
class m151005_151946_install extends Migration
{

public function up()
{
$tableOptions = null;
Expand Down Expand Up @@ -52,11 +51,28 @@ public function up()
], $tableOptions);

// Add Indexes for performance optimization
$this->createIndex('rp_role_id_composite', Constants::TABLE_ROLE_PERMISSIONS, ['role_id', 'permission_id'], true);
$this->createIndex(
'rp_role_id_composite',
Constants::TABLE_ROLE_PERMISSIONS,
['role_id', 'permission_id'],
true
);

// Add Foreign Keys
$this->addForeignKey('rp_roles_role_id', Constants::TABLE_ROLE_PERMISSIONS, 'role_id', Constants::TABLE_ROLES, 'id');
$this->addForeignKey('rp_roles_permission_id', Constants::TABLE_ROLE_PERMISSIONS, 'permission_id', Constants::TABLE_PERMISSIONS, 'id');
$this->addForeignKey(
'rp_roles_role_id',
Constants::TABLE_ROLE_PERMISSIONS,
'role_id',
Constants::TABLE_ROLES,
'id'
);
$this->addForeignKey(
'rp_roles_permission_id',
Constants::TABLE_ROLE_PERMISSIONS,
'permission_id',
Constants::TABLE_PERMISSIONS,
'id'
);
}

public function down()
Expand Down
1 change: 0 additions & 1 deletion migrations/m170914_110639_alter_roles_permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public function down()
$this->boolean()->defaultValue(1)
);


$this->dropIndex(
'k_' . Constants::TABLE_PERMISSIONS . '_status',
Constants::TABLE_PERMISSIONS
Expand Down
3 changes: 2 additions & 1 deletion src/BasePermissionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function canAccess($permissionKey)
}

/**
* @param $roleKey
* @author Adegoke Obasa <[email protected]>
*/
public function setRoleByKey($roleKey)
Expand All @@ -38,9 +39,9 @@ public function setRoleByKey($roleKey)
}

/**
* @author Adegoke Obasa <[email protected]>
* @param $roleId
* @return void
* @author Adegoke Obasa <[email protected]>
*/
public function setRoleById($roleId)
{
Expand Down
18 changes: 10 additions & 8 deletions src/DbPermissionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,61 +8,62 @@
use cottacush\rbac\libs\Constants;
use cottacush\rbac\models\Permission;
use cottacush\rbac\models\Role;
use Yii;

class DbPermissionManager extends BasePermissionManager
{
/**
* @author Adegoke Obasa <[email protected]>
* @return mixed
* @author Adegoke Obasa <[email protected]>
*/
public function getRoles()
{
return Role::find()->asArray()->all();
}

/**
* @author Adegoke Obasa <[email protected]>
* @param $key
* @return Role
* @author Adegoke Obasa <[email protected]>
*/
public function getRole($key)
{
return Role::find()->where(['key' => $key, 'status' => Constants::STATUS_ACTIVE])->limit(1)->one();
}

/**
* @author Adegoke Obasa <[email protected]>
* @param $roleId
* @return Role
* @author Adegoke Obasa <[email protected]>
*/
public function getRoleById($roleId)
{
return Role::find()->where(['id' => $roleId, 'status' => Constants::STATUS_ACTIVE])->limit(1)->one();
}

/**
* @author Adegoke Obasa <[email protected]>
* @return mixed
* @author Adegoke Obasa <[email protected]>
*/
public function getPermissions()
{
return Permission::find()->asArray()->all();
}

/**
* @author Adegoke Obasa <[email protected]>
* @param $key
* @return Permission
* @author Adegoke Obasa <[email protected]>
*/
public function getPermission($key)
{
return Permission::find()->where(['key' => $key, 'status' => Constants::STATUS_ACTIVE])->limit(1)->one();
}

/**
* @author Adegoke Obasa <[email protected]>
* @param $permissionId
* @return Permission
* @author Adegoke Obasa <[email protected]>
*/
public function getPermissionById($permissionId)
{
Expand All @@ -71,17 +72,18 @@ public function getPermissionById($permissionId)
}

/**
* @author Adegoke Obasa <[email protected]>
* @return mixed
* @author Adegoke Obasa <[email protected]>
*/
public function getUserRole()
{
$role = \Yii::$app->session->get($this->sessionPrefix . '::user_role');
$role = Yii::$app->session->get($this->sessionPrefix . '::user_role');
return $role;
}

/**
* @inheritdoc
* @throws \yii\base\InvalidConfigException
* @author Adegoke Obasa <[email protected]>
*/
public function getUserPermissions()
Expand Down
22 changes: 11 additions & 11 deletions src/ManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,75 +10,75 @@ interface ManagerInterface
{
/**
* Checks if the user has the specified permission.
* @author Adegoke Obasa <[email protected]>
* @param $permissionKey
* @return mixed
* @author Adegoke Obasa <[email protected]>
*/
public function canAccess($permissionKey);

/**
* @author Adegoke Obasa <[email protected]>
* @return mixed
* @author Adegoke Obasa <[email protected]>
*/
public function getRoles();

/**
* @author Adegoke Obasa <[email protected]>
* @return mixed
* @author Adegoke Obasa <[email protected]>
*/
public function getUserRole();

/**
* @author Adegoke Obasa <[email protected]>
* @param $key
* @return mixed
* @author Adegoke Obasa <[email protected]>
*/
public function getRole($key);

/**
* @author Adegoke Obasa <[email protected]>
* @param $roleId
* @return mixed
* @author Adegoke Obasa <[email protected]>
*/
public function getRoleById($roleId);

/**
* @author Adegoke Obasa <[email protected]>
* @return mixed
* @author Adegoke Obasa <[email protected]>
*/
public function getPermissions();

/**
* @author Adegoke Obasa <[email protected]>
* @param $key
* @return mixed
* @author Adegoke Obasa <[email protected]>
*/
public function getPermission($key);

/**
* @author Adegoke Obasa <[email protected]>
* @param $permissionId
* @return mixed
* @author Adegoke Obasa <[email protected]>
*/
public function getPermissionById($permissionId);

/**
* @author Adegoke Obasa <[email protected]>
* @param $roleKey
* @return mixed
* @author Adegoke Obasa <[email protected]>
*/
public function setRoleByKey($roleKey);

/**
* @author Adegoke Obasa <[email protected]>
* @param $roleId
* @return mixed
* @author Adegoke Obasa <[email protected]>
*/
public function setRoleById($roleId);

/**
* @author Adegoke Obasa <[email protected]>
* @return mixed
* @author Adegoke Obasa <[email protected]>
*/
public function getUserPermissions();
}
6 changes: 0 additions & 6 deletions src/libs/Constants.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
<?php
/**
* Created by PhpStorm.
* User: Lawale
* Date: 14/09/2017
* Time: 12:07
*/

namespace cottacush\rbac\libs;

Expand Down
3 changes: 2 additions & 1 deletion src/models/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ public function getRolePermissions()

/**
* Get Permissions assigned to role
* @author Adegoke Obasa <[email protected]>
* @return mixed
* @throws \yii\base\InvalidConfigException
* @author Adegoke Obasa <[email protected]>
*/
public function getPermissions()
{
Expand Down

0 comments on commit d1b6e1d

Please sign in to comment.