1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
// --------------------------------------------------------------------- |
4
|
|
|
// |
5
|
|
|
// Copyright (C) 2018-2024 Artem Rodygin |
6
|
|
|
// |
7
|
|
|
// You should have received a copy of the MIT License along with |
8
|
|
|
// this file. If not, see <https://opensource.org/licenses/MIT>. |
9
|
|
|
// |
10
|
|
|
// --------------------------------------------------------------------- |
11
|
|
|
|
12
|
|
|
namespace Linode\Images\Repository; |
13
|
|
|
|
14
|
|
|
use Linode\Entity; |
15
|
|
|
use Linode\Images\Image; |
16
|
|
|
use Linode\Images\ImageRepositoryInterface; |
17
|
|
|
use Linode\Internal\AbstractRepository; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @codeCoverageIgnore This class was autogenerated. |
21
|
|
|
*/ |
22
|
|
|
class ImageRepository extends AbstractRepository implements ImageRepositoryInterface |
23
|
|
|
{ |
24
|
|
|
public function createImage(array $parameters = []): Image |
25
|
|
|
{ |
26
|
|
|
$response = $this->client->post($this->getBaseUri(), $parameters); |
27
|
|
|
$contents = $response->getBody()->getContents(); |
28
|
|
|
$json = json_decode($contents, true); |
29
|
|
|
|
30
|
|
|
return new Image($this->client, $json); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function updateImage(string $imageId, array $parameters = []): Image |
34
|
|
|
{ |
35
|
|
|
$response = $this->client->put(sprintf('%s/%s', $this->getBaseUri(), $imageId), $parameters); |
36
|
|
|
$contents = $response->getBody()->getContents(); |
37
|
|
|
$json = json_decode($contents, true); |
38
|
|
|
|
39
|
|
|
return new Image($this->client, $json); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function deleteImage(string $imageId): void |
43
|
|
|
{ |
44
|
|
|
$this->client->delete(sprintf('%s/%s', $this->getBaseUri(), $imageId)); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function uploadImage(array $parameters = []): Image |
48
|
|
|
{ |
49
|
|
|
$response = $this->client->post(sprintf('%s/upload', $this->getBaseUri()), $parameters); |
50
|
|
|
$contents = $response->getBody()->getContents(); |
51
|
|
|
$json = json_decode($contents, true); |
52
|
|
|
|
53
|
|
|
return new Image($this->client, $json['image']); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
protected function getBaseUri(): string |
57
|
|
|
{ |
58
|
|
|
return '/images'; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
protected function getSupportedFields(): array |
62
|
|
|
{ |
63
|
|
|
return [ |
64
|
|
|
Image::FIELD_ID, |
65
|
|
|
Image::FIELD_LABEL, |
66
|
|
|
Image::FIELD_VENDOR, |
67
|
|
|
Image::FIELD_DESCRIPTION, |
68
|
|
|
Image::FIELD_IS_PUBLIC, |
69
|
|
|
Image::FIELD_SIZE, |
70
|
|
|
Image::FIELD_STATUS, |
71
|
|
|
Image::FIELD_CREATED, |
72
|
|
|
Image::FIELD_UPDATED, |
73
|
|
|
Image::FIELD_CREATED_BY, |
74
|
|
|
Image::FIELD_DEPRECATED, |
75
|
|
|
Image::FIELD_TYPE, |
76
|
|
|
Image::FIELD_EXPIRY, |
77
|
|
|
Image::FIELD_EOL, |
78
|
|
|
]; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
protected function jsonToEntity(array $json): Entity |
82
|
|
|
{ |
83
|
|
|
return new Image($this->client, $json); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|