for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Created on 13/02/18 by enea dhack.
*/
namespace Enea\Authorization\Operators;
use Enea\Authorization\Contracts\{
Grantable, PermissionsOwner, RolesOwner
};
use Enea\Authorization\Events\Operation;
use Enea\Authorization\Exceptions\{
GrantableIsNotValidModelException
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
abstract class Operator
{
private $event;
public function __construct(Dispatcher $event)
$this->event = $event;
}
abstract public function permissions(PermissionsOwner $owner, Collection $permissions): void;
abstract public function roles(RolesOwner $owner, Collection $roles): void;
protected function castToModel(Grantable $grantable): Model
if (! $grantable instanceof Model) {
throw GrantableIsNotValidModelException::make($grantable);
return $grantable;
protected function dispatchEvent(Operation $operation): void
$this->event->dispatch($operation);