-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fad2e2d
commit 865227b
Showing
14 changed files
with
727 additions
and
337 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace Silber\Bouncer\Conductors; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Silber\Bouncer\Conductors\Traits\ConductsAbilities; | ||
use Silber\Bouncer\Conductors\Traits\AssociatesAbilities; | ||
|
||
class ForbidsAbility | ||
{ | ||
use AssociatesAbilities, ConductsAbilities; | ||
|
||
/** | ||
* The authority to be forbidden from the abilities. | ||
* | ||
* @var \Illuminate\Database\Eloquent\Model|string | ||
*/ | ||
protected $authority; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param \Illuminate\Database\Eloquent\Model|string $authority | ||
*/ | ||
public function __construct($authority) | ||
{ | ||
$this->authority = $authority; | ||
} | ||
|
||
/** | ||
* Forbid the abilities to the authority. | ||
* | ||
* @param mixed $abilities | ||
* @param \Illuminate\Database\Eloquent\Model|string|null $model | ||
* @param bool $onlyOwned | ||
* @return bool | ||
*/ | ||
public function to($abilities, $model = null, $onlyOwned = false) | ||
{ | ||
$ids = $this->getAbilityIds($abilities, $model, $onlyOwned); | ||
|
||
$this->forbidAbilities($ids, $this->getAuthority()); | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Associate the given abilitiy IDs as forbidden abilities. | ||
* | ||
* @param array $ids | ||
* @param \Illuminate\Database\Eloquent\Model $authority | ||
* @return void | ||
*/ | ||
protected function forbidAbilities(array $ids, Model $authority) | ||
{ | ||
$ids = array_diff($ids, $this->getAssociatedAbilityIds($authority, $ids, true)); | ||
|
||
$authority->abilities()->attach($ids, ['forbidden' => true]); | ||
} | ||
} |
Oops, something went wrong.