mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
a2381e44a7
Update Company Service Class Create Documents Service Class Create File Service Class Base64 File Convert Service Class File Upload Storage Service Class
48 lines
1.1 KiB
PHP
48 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\General\Abstracts;
|
|
|
|
|
|
use App\Classes\Exceptions\RequestValidationException;
|
|
use App\Classes\Interfaces\DataTransferObject;
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
abstract class AbstractValidation
|
|
{
|
|
|
|
/** @var Validator */
|
|
private $validator;
|
|
|
|
/**
|
|
* AbstractValidation constructor.
|
|
* @param Validator $validator
|
|
*/
|
|
public function __construct(Validator $validator)
|
|
{
|
|
$this->validator = $validator;
|
|
}
|
|
|
|
|
|
abstract protected function data($object): array;
|
|
|
|
abstract protected function rules(): array;
|
|
|
|
abstract protected function messages(): array;
|
|
|
|
/**
|
|
* @param DataTransferObject $object
|
|
* @return bool
|
|
* @throws RequestValidationException
|
|
*/
|
|
public function validate(DataTransferObject $object, ?string $type = 'POST')
|
|
{
|
|
$validator = $this->validator::make($this->data($object), $this->rules($type), $this->messages());
|
|
|
|
if($validator->fails()) {
|
|
throw new RequestValidationException($validator->messages()->first());
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
} |