service-captcha/app/Services/Service.php

55 lines
1.4 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace App\Services;
use App\ServiceResults\ServiceResultArray;
use App\ServiceResults\ServiceResultError;
abstract class Service
{
final protected function errValidate(string $message, array $errors = []): ServiceResultError
{
return $this->error(422, $message, $errors);
}
final protected function errFobidden(string $message): ServiceResultError
{
return $this->error(403, $message);
}
final protected function errNotFound(string $message): ServiceResultError
{
return $this->error(404, $message);
}
final protected function errService(string $message): ServiceResultError
{
return $this->error(500, $message);
}
final protected function notAcceptable(string $message): ServiceResultError
{
return $this->error(406, $message);
}
final protected function ok(string $message = 'OK'): ServiceResultArray
{
return $this->result(['message' => $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
);
}
}