-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
ImageData.php
42 lines (37 loc) 路 1.04 KB
/
ImageData.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
namespace BenBjurstrom\CloudflareImages\Data;
use Exception;
use Saloon\Contracts\Response;
final class ImageData
{
/**
* @param array<int, string> $variants
* @param array<int, string> $metadata
*/
public function __construct(
public string $id,
public ?string $filename,
public string $uploaded,
public bool $requireSignedURLs,
public array $variants,
public array $metadata,
public bool $isDraft,
) {
}
public static function fromResponse(Response $response): self
{
$data = $response->json('result');
if (! is_array($data)) {
throw new Exception('Invalid response');
}
return new self(
id: $data['id'],
filename: $data['filename'],
uploaded: $data['uploaded'],
requireSignedURLs: $data['requireSignedURLs'],
variants: $data['variants'],
metadata: $data['meta'] ?? [],
isDraft: $data['draft'] ?? false,
);
}
}