|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace CodebarAg\MFiles\DTO; |
| 6 | + |
| 7 | +use Illuminate\Support\Arr; |
| 8 | + |
| 9 | +final class MFilesError |
| 10 | +{ |
| 11 | + public function __construct( |
| 12 | + public readonly string $errorCode, |
| 13 | + public readonly int $status, |
| 14 | + public readonly string $url, |
| 15 | + public readonly string $method, |
| 16 | + public readonly ?Exception $exception, |
| 17 | + public readonly ?string $stack, |
| 18 | + public readonly string $message, |
| 19 | + public readonly bool $isLoggedToVault, |
| 20 | + public readonly bool $isLoggedToApplication, |
| 21 | + public readonly string $exceptionName, |
| 22 | + ) {} |
| 23 | + |
| 24 | + public static function fromArray(array $data): self |
| 25 | + { |
| 26 | + $exceptionData = Arr::get($data, 'Exception'); |
| 27 | + $exception = $exceptionData ? Exception::fromArray($exceptionData) : null; |
| 28 | + |
| 29 | + return new self( |
| 30 | + errorCode: Arr::get($data, 'ErrorCode', ''), |
| 31 | + status: Arr::get($data, 'Status', 0), |
| 32 | + url: Arr::get($data, 'URL', ''), |
| 33 | + method: Arr::get($data, 'Method', ''), |
| 34 | + exception: $exception, |
| 35 | + stack: Arr::get($data, 'Stack'), |
| 36 | + message: Arr::get($data, 'Message', ''), |
| 37 | + isLoggedToVault: Arr::get($data, 'IsLoggedToVault', false), |
| 38 | + isLoggedToApplication: Arr::get($data, 'IsLoggedToApplication', false), |
| 39 | + exceptionName: Arr::get($data, 'ExceptionName', ''), |
| 40 | + ); |
| 41 | + } |
| 42 | + |
| 43 | + public function toArray(): array |
| 44 | + { |
| 45 | + return [ |
| 46 | + 'errorCode' => $this->errorCode, |
| 47 | + 'status' => $this->status, |
| 48 | + 'url' => $this->url, |
| 49 | + 'method' => $this->method, |
| 50 | + 'exception' => $this->exception?->toArray(), |
| 51 | + 'stack' => $this->stack, |
| 52 | + 'message' => $this->message, |
| 53 | + 'isLoggedToVault' => $this->isLoggedToVault, |
| 54 | + 'isLoggedToApplication' => $this->isLoggedToApplication, |
| 55 | + 'exceptionName' => $this->exceptionName, |
| 56 | + ]; |
| 57 | + } |
| 58 | +} |
0 commit comments