69 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			69 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| declare(strict_types=1);
 | |
| 
 | |
| namespace App\Services;
 | |
| 
 | |
| use App\ServiceResults\ServiceResultArray;
 | |
| use App\ServiceResults\ServiceResultError;
 | |
| use App\ServiceResults\ServiceResultSuccess;
 | |
| use App\ServiceResults\StoreUpdateResult;
 | |
| use Illuminate\Database\Eloquent\Model;
 | |
| use Illuminate\Http\Response;
 | |
| 
 | |
| abstract class Service
 | |
| {
 | |
|     final protected function errValidate(string $message, array $errors = []): ServiceResultError
 | |
|     {
 | |
|         return $this->error(Response::HTTP_UNPROCESSABLE_ENTITY, $message, $errors);
 | |
|     }
 | |
| 
 | |
|     final protected function errFobidden(string $message): ServiceResultError
 | |
|     {
 | |
|         return $this->error(Response::HTTP_FORBIDDEN, $message);
 | |
|     }
 | |
| 
 | |
|     final protected function errNotFound(string $message): ServiceResultError
 | |
|     {
 | |
|         return $this->error(Response::HTTP_NOT_FOUND, $message);
 | |
|     }
 | |
| 
 | |
|     final protected function errService(string $message): ServiceResultError
 | |
|     {
 | |
|         return $this->error(Response::HTTP_INTERNAL_SERVER_ERROR, $message);
 | |
|     }
 | |
| 
 | |
|     final protected function notAcceptable(string $message): ServiceResultError
 | |
|     {
 | |
|         return $this->error(Response::HTTP_NOT_ACCEPTABLE, $message);
 | |
|     }
 | |
| 
 | |
|     final protected function errUnauthorized(string $message): ServiceResultError
 | |
|     {
 | |
|         return $this->error(Response::HTTP_UNAUTHORIZED, $message);
 | |
|     }
 | |
| 
 | |
|     final protected function ok(string $message = 'OK'): ServiceResultSuccess
 | |
|     {
 | |
|         return new ServiceResultSuccess($message);
 | |
|     }
 | |
| 
 | |
|     final protected function resultStoreUpdateModel(Model $model, string $message = 'OK'): StoreUpdateResult
 | |
|     {
 | |
|         return new StoreUpdateResult($model, $message);
 | |
|     }
 | |
| 
 | |
|     final protected function result(array $data = []): ServiceResultArray
 | |
|     {
 | |
|         return new ServiceResultArray(data: $data);
 | |
|     }
 | |
| 
 | |
|     final protected function error(int $code, string $message, array $errors = []): ServiceResultError
 | |
|     {
 | |
|         return new ServiceResultError(
 | |
|             message: $message,
 | |
|             errors: $errors,
 | |
|             code: $code
 | |
|         );
 | |
|     }
 | |
| }
 |