File "OpenApiExceptionsResponse.php"
Full Path: /var/www/html/back/app/Attributes/OpenApiExceptionsResponse.php
File size: 1022 B
MIME-type: text/x-php
Charset: utf-8
<?php
declare(strict_types=1);
namespace App\Attributes;
use AllowDynamicProperties;
use App\Responses\Shared\Dto;
use Attribute;
use Knuckles\Scribe\Attributes\Response as ResponseAttribute;
#[AllowDynamicProperties]
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_FUNCTION | Attribute::TARGET_METHOD | Attribute::TARGET_CLASS)]
class OpenApiExceptionsResponse extends ResponseAttribute
{
public function __construct(
public string $class,
public string $method,
) {
}
public function toArray(): array
{
$exceptions = Dto::getMethodExceptions($this->class, $this->method);
$a = collect($exceptions)->map(function ($exception) {
$u = 'App\\Exceptions\\' . $exception;
$s = new $u();
return [
'status' => $s->json()->getStatusCode(),
'content' => $s->json()->getContent(),
'description' => $exception,
];
})->toArray();
return $a[1];
}
}