for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
/**
* @author enea dhack <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Enea\Authorization\Operators;
use Enea\Authorization\Contracts\DeniableOwner;
use Enea\Authorization\Contracts\PermissionContract;
use Enea\Authorization\Events\Denied;
use Enea\Authorization\Exceptions\AuthorizationNotDeniedException;
use Exception;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Support\Collection;
class Denier
{
private $event;
public function __construct(Dispatcher $event)
$this->event = $event;
}
public function deny(DeniableOwner $owner, Collection $permissions): void
$permissions->each(function (PermissionContract $permission) use ($owner) {
$this->save($owner, $permission);
});
$this->event->dispatch(new Denied($owner, $permissions));
protected function save(DeniableOwner $owner, PermissionContract $permission): void
try {
$owner->denied()->save($permission);
} catch (Exception $exception) {
throw new AuthorizationNotDeniedException($permission, $exception);