2023-06-28 14:36:51 +06:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace App\ServiceResults;
|
|
|
|
|
|
|
|
use App\Contracts\ServiceResultError as ServiceResultErrorContract;
|
|
|
|
|
|
|
|
final class ServiceResultError extends ServiceResult implements ServiceResultErrorContract
|
|
|
|
{
|
|
|
|
public function __construct(
|
|
|
|
private readonly string $message,
|
|
|
|
private readonly array $errors = [],
|
|
|
|
private readonly ?int $code = null,
|
|
|
|
) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getMessage(): string
|
|
|
|
{
|
|
|
|
return $this->message;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCode(): ?int
|
|
|
|
{
|
|
|
|
return $this->code;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getErrors(): array
|
|
|
|
{
|
|
|
|
return $this->errors;
|
|
|
|
}
|
|
|
|
|
2023-07-16 19:21:09 +06:00
|
|
|
public function getErrorsOrMessage(): array|string
|
|
|
|
{
|
|
|
|
if (!empty($this->getErrors())) {
|
|
|
|
return $this->getErrors();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->getMessage();
|
|
|
|
}
|
|
|
|
|
2023-06-28 14:36:51 +06:00
|
|
|
public function getData(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'message' => $this->getMessage(),
|
|
|
|
'errors' => $this->errors
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|