|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace InShore\Bookwhen\Responses\ClassPasses; |
|
6
|
|
|
|
|
7
|
|
|
use InShore\Bookwhen\Contracts\ResponseContract; |
|
8
|
|
|
use InShore\Bookwhen\Responses\Concerns\ArrayAccessible; |
|
9
|
|
|
use InShore\Bookwhen\Responses\ClassPasses\RetrieveResponse; |
|
10
|
|
|
|
|
11
|
|
|
//use InShore\Bookwhen\Testing\Responses\Concerns\Fakeable; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @implements ResponseContract<array{object: string, data: array<int, array{id: string, object: string, created_at: int, bytes: int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null}>}> |
|
15
|
|
|
*/ |
|
16
|
|
|
final class ListResponse implements ResponseContract |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @use ArrayAccessible<array{object: string, data: array<int, array{id: string, object: string, created_at: int, bytes: int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null}>}> |
|
20
|
|
|
*/ |
|
21
|
|
|
use ArrayAccessible; |
|
22
|
|
|
|
|
23
|
|
|
// use Fakeable; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param array<int, RetrieveResponse> $data |
|
27
|
|
|
*/ |
|
28
|
|
|
private function __construct( |
|
29
|
|
|
public readonly array $data, |
|
30
|
|
|
) { |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Acts as static factory, and returns a new Response instance. |
|
35
|
|
|
* |
|
36
|
|
|
* @param array{data: array<int, array{event_id: string, object: string, created_at: int, bytes: int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null}>} $attributes |
|
|
|
|
|
|
37
|
|
|
*/ |
|
38
|
|
|
public static function from(array $attributes): self |
|
39
|
|
|
{ |
|
40
|
|
|
$data = array_map(fn (array $result): RetrieveResponse => RetrieveResponse::from( |
|
41
|
|
|
$result |
|
42
|
|
|
), $attributes['data']); |
|
43
|
|
|
|
|
44
|
|
|
return new self( |
|
45
|
|
|
$data, |
|
46
|
|
|
); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* {@inheritDoc} |
|
51
|
|
|
*/ |
|
52
|
|
|
public function toArray(): array |
|
53
|
|
|
{ |
|
54
|
|
|
return [ |
|
55
|
|
|
'object' => $this->object, |
|
|
|
|
|
|
56
|
|
|
'data' => array_map( |
|
57
|
|
|
static fn (RetrieveResponse $response): array => $response->toArray(), |
|
58
|
|
|
$this->data, |
|
59
|
|
|
), |
|
60
|
|
|
]; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|