Skip to content

Commit

Permalink
Merge pull request #2 from ademarcy/master
Browse files Browse the repository at this point in the history
Massive resource-centric permissions clearing
  • Loading branch information
chdeliens committed May 19, 2016
2 parents acac488 + aa934a4 commit 0ee1754
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Drivers/ArrayDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,18 @@ public function hasRolePermission(Role $role, Permission $permission)
return false;
}

/**
* Removes all permissions for a resource, used
* for performance-critical massive removals.
*
* @param \BeatSwitch\Lock\Resources\Resource
* @return void
*/
public function clearPermissionsForResource(Resource $resource)
{
throw new \Exception('Unimplemented method "ArrayDriver::clearPermissionsForResource"');
}

/**
* Creates a key to store the caller's permissions
*
Expand Down
10 changes: 10 additions & 0 deletions src/Drivers/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use BeatSwitch\Lock\Callers\Caller;
use BeatSwitch\Lock\Permissions\Permission;
use BeatSwitch\Lock\Roles\Role;
use BeatSwitch\Lock\Resources\Resource;

/**
* A contract to identify an implementation to store permissions to
Expand Down Expand Up @@ -82,4 +83,13 @@ public function removeRolePermission(Role $role, Permission $permission);
* @return bool
*/
public function hasRolePermission(Role $role, Permission $permission);

/**
* Removes all permissions for a resource, used
* for performance-critical massive removals.
*
* @param \BeatSwitch\Lock\Resources\Resource
* @return void
*/
public function clearPermissionsForResource(Resource $resource);
}
14 changes: 14 additions & 0 deletions src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,20 @@ protected function findRole($role)
return new SimpleRole($role);
}

/**
* Clear permissions for several resources (used
* for performance-critical massive removals).
*
* @param array $resources an array of Resource objects
* @return void
*/
public function clearPermissionsForResources(array $resources)
{
foreach($resources as $resource) {
$this->driver->clearPermissionsForResource($resource);
}
}

/**
* @return \BeatSwitch\Lock\Drivers\Driver
*/
Expand Down

0 comments on commit 0ee1754

Please sign in to comment.