Skip to content

Commit

Permalink
Remove the getClipboardInstance() methods (#505)
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephSilber authored Feb 21, 2020
1 parent a1ea4e0 commit bc9d735
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 58 deletions.
16 changes: 3 additions & 13 deletions src/Database/Concerns/Authorizable.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ trait Authorizable
*/
public function can($ability, $model = null)
{
return $this->getClipboardInstance()->check($this, $ability, $model);
return Container::getInstance()
->make(Clipboard::class)
->check($this, $ability, $model);
}

/**
Expand All @@ -42,16 +44,4 @@ public function cannot($ability, $model = null)
{
return $this->cant($ability, $model);
}

/**
* Get an instance of the bouncer's clipboard.
*
* @return \Silber\Bouncer\Contracts\Clipboard
*/
protected function getClipboardInstance()
{
$container = Container::getInstance() ?: new Container;

return $container->make(Clipboard::class);
}
}
20 changes: 6 additions & 14 deletions src/Database/Concerns/HasAbilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ public function abilities()
*/
public function getAbilities()
{
return $this->getClipboardInstance()->getAbilities($this);
return Container::getInstance()
->make(Clipboard::class)
->getAbilities($this);
}

/**
Expand All @@ -59,7 +61,9 @@ public function getAbilities()
*/
public function getForbiddenAbilities()
{
return $this->getClipboardInstance()->getAbilities($this, false);
return Container::getInstance()
->make(Clipboard::class)
->getAbilities($this, false);
}

/**
Expand Down Expand Up @@ -133,16 +137,4 @@ public function unforbid($ability = null, $model = null)

return $this;
}

/**
* Get an instance of the bouncer's clipboard.
*
* @return \Silber\Bouncer\Contracts\Clipboard
*/
protected function getClipboardInstance()
{
$container = Container::getInstance() ?: new Container;

return $container->make(Clipboard::class);
}
}
34 changes: 12 additions & 22 deletions src/Database/Concerns/HasRoles.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public function roles()
*/
public function getRoles()
{
return $this->getClipboardInstance()->getRoles($this);
return Container::getInstance()
->make(Clipboard::class)
->getRoles($this);
}

/**
Expand Down Expand Up @@ -87,9 +89,9 @@ public function isAn($role)
{
$roles = func_get_args();

$clipboard = $this->getClipboardInstance();

return $clipboard->checkRole($this, $roles, 'or');
return Container::getInstance()
->make(Clipboard::class)
->checkRole($this, $roles, 'or');
}

/**
Expand All @@ -115,9 +117,9 @@ public function isNotAn($role)
{
$roles = func_get_args();

$clipboard = $this->getClipboardInstance();

return $clipboard->checkRole($this, $roles, 'not');
return Container::getInstance()
->make(Clipboard::class)
->checkRole($this, $roles, 'not');
}

/**
Expand All @@ -143,9 +145,9 @@ public function isAll($role)
{
$roles = func_get_args();

$clipboard = $this->getClipboardInstance();

return $clipboard->checkRole($this, $roles, 'and');
return Container::getInstance()
->make(Clipboard::class)
->checkRole($this, $roles, 'and');
}

/**
Expand Down Expand Up @@ -192,16 +194,4 @@ public function scopeWhereIsNot($query, $role)
func_get_args()
);
}

/**
* Get an instance of the bouncer's clipboard.
*
* @return \Silber\Bouncer\Contracts\Clipboard
*/
protected function getClipboardInstance()
{
$container = Container::getInstance() ?: new Container;

return $container->make(Clipboard::class);
}
}
4 changes: 1 addition & 3 deletions src/Database/Concerns/IsRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

trait IsRole
{
use HasAbilities, Authorizable {
HasAbilities::getClipboardInstance insteadof Authorizable;
}
use HasAbilities, Authorizable;

/**
* Boot the is role trait.
Expand Down
4 changes: 1 addition & 3 deletions src/Database/HasRolesAndAbilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@

trait HasRolesAndAbilities
{
use HasRoles, HasAbilities {
HasRoles::getClipboardInstance insteadof HasAbilities;
}
use HasRoles, HasAbilities;
}
4 changes: 1 addition & 3 deletions tests/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,7 @@ protected function dispatcher()

class User extends Eloquent
{
use Authorizable, HasRolesAndAbilities {
Authorizable::getClipboardInstance insteadof HasRolesAndAbilities;
}
use Authorizable, HasRolesAndAbilities;

protected $table = 'users';

Expand Down

0 comments on commit bc9d735

Please sign in to comment.