mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\General\Abstracts;
|
|
|
|
|
|
use App\Classes\Exceptions\AccessForbiddenException;
|
|
use App\Classes\Exceptions\RequestValidationException;
|
|
use App\Classes\General\Interfaces\DataTransferObject;
|
|
|
|
abstract class AbstractRule
|
|
{
|
|
|
|
abstract protected function authorized(): bool;
|
|
|
|
abstract protected function validators($object): bool;
|
|
|
|
|
|
abstract protected function criteria($object): bool;
|
|
|
|
|
|
/**
|
|
* @param DataTransferObject|null $object
|
|
* @return bool
|
|
* @throws AccessForbiddenException
|
|
* @throws RequestValidationException
|
|
*/
|
|
public function passes(?DataTransferObject $object = null): bool {
|
|
try {
|
|
if(!$this->authorized()){
|
|
throw new AccessForbiddenException('You don\'t have permission to preform this action');
|
|
}
|
|
|
|
$this->validators($object);
|
|
$this->criteria($object);
|
|
|
|
return true;
|
|
|
|
} catch(AccessForbiddenException $exception){
|
|
throw new AccessForbiddenException('You don\'t have permission to preform this action');
|
|
} catch(\Exception $exception){
|
|
throw new RequestValidationException($exception->getMessage());
|
|
}
|
|
|
|
}
|
|
|
|
} |