Skip to content

Commit 0b65863

Browse files
feat(client): use real enums
1 parent 1329184 commit 0b65863

File tree

115 files changed

+932
-1400
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+932
-1400
lines changed

src/Assets/AssetListParams.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@
2929
* @see ImageKit\Assets->list
3030
*
3131
* @phpstan-type asset_list_params = array{
32-
* fileType?: FileType::*,
32+
* fileType?: FileType|value-of<FileType>,
3333
* limit?: int,
3434
* path?: string,
3535
* searchQuery?: string,
3636
* skip?: int,
37-
* sort?: Sort::*,
38-
* type?: Type::*,
37+
* sort?: Sort|value-of<Sort>,
38+
* type?: Type|value-of<Type>,
3939
* }
4040
*/
4141
final class AssetListParams implements BaseModel
@@ -51,7 +51,7 @@ final class AssetListParams implements BaseModel
5151
* - `image` — include only image files
5252
* - `non-image` — include only non-image files (e.g., JS, CSS, video)
5353
*
54-
* @var FileType::*|null $fileType
54+
* @var value-of<FileType>|null $fileType
5555
*/
5656
#[Api(enum: FileType::class, optional: true)]
5757
public ?string $fileType;
@@ -94,7 +94,7 @@ final class AssetListParams implements BaseModel
9494
/**
9595
* Sort the results by one of the supported fields in ascending or descending order.
9696
*
97-
* @var Sort::*|null $sort
97+
* @var value-of<Sort>|null $sort
9898
*/
9999
#[Api(enum: Sort::class, optional: true)]
100100
public ?string $sort;
@@ -107,7 +107,7 @@ final class AssetListParams implements BaseModel
107107
* - `folder` — returns only folders
108108
* - `all` — returns both files and folders (excludes `file-version`)
109109
*
110-
* @var Type::*|null $type
110+
* @var value-of<Type>|null $type
111111
*/
112112
#[Api(enum: Type::class, optional: true)]
113113
public ?string $type;
@@ -122,28 +122,28 @@ public function __construct()
122122
*
123123
* You must use named parameters to construct any parameters with a default value.
124124
*
125-
* @param FileType::* $fileType
126-
* @param Sort::* $sort
127-
* @param Type::* $type
125+
* @param FileType|value-of<FileType> $fileType
126+
* @param Sort|value-of<Sort> $sort
127+
* @param Type|value-of<Type> $type
128128
*/
129129
public static function with(
130-
?string $fileType = null,
130+
FileType|string|null $fileType = null,
131131
?int $limit = null,
132132
?string $path = null,
133133
?string $searchQuery = null,
134134
?int $skip = null,
135-
?string $sort = null,
136-
?string $type = null,
135+
Sort|string|null $sort = null,
136+
Type|string|null $type = null,
137137
): self {
138138
$obj = new self;
139139

140-
null !== $fileType && $obj->fileType = $fileType;
140+
null !== $fileType && $obj->fileType = $fileType instanceof FileType ? $fileType->value : $fileType;
141141
null !== $limit && $obj->limit = $limit;
142142
null !== $path && $obj->path = $path;
143143
null !== $searchQuery && $obj->searchQuery = $searchQuery;
144144
null !== $skip && $obj->skip = $skip;
145-
null !== $sort && $obj->sort = $sort;
146-
null !== $type && $obj->type = $type;
145+
null !== $sort && $obj->sort = $sort instanceof Sort ? $sort->value : $sort;
146+
null !== $type && $obj->type = $type instanceof Type ? $type->value : $type;
147147

148148
return $obj;
149149
}
@@ -155,12 +155,12 @@ public static function with(
155155
* - `image` — include only image files
156156
* - `non-image` — include only non-image files (e.g., JS, CSS, video)
157157
*
158-
* @param FileType::* $fileType
158+
* @param FileType|value-of<FileType> $fileType
159159
*/
160-
public function withFileType(string $fileType): self
160+
public function withFileType(FileType|string $fileType): self
161161
{
162162
$obj = clone $this;
163-
$obj->fileType = $fileType;
163+
$obj->fileType = $fileType instanceof FileType ? $fileType->value : $fileType;
164164

165165
return $obj;
166166
}
@@ -223,12 +223,12 @@ public function withSkip(int $skip): self
223223
/**
224224
* Sort the results by one of the supported fields in ascending or descending order.
225225
*
226-
* @param Sort::* $sort
226+
* @param Sort|value-of<Sort> $sort
227227
*/
228-
public function withSort(string $sort): self
228+
public function withSort(Sort|string $sort): self
229229
{
230230
$obj = clone $this;
231-
$obj->sort = $sort;
231+
$obj->sort = $sort instanceof Sort ? $sort->value : $sort;
232232

233233
return $obj;
234234
}
@@ -241,12 +241,12 @@ public function withSort(string $sort): self
241241
* - `folder` — returns only folders
242242
* - `all` — returns both files and folders (excludes `file-version`)
243243
*
244-
* @param Type::* $type
244+
* @param Type|value-of<Type> $type
245245
*/
246-
public function withType(string $type): self
246+
public function withType(Type|string $type): self
247247
{
248248
$obj = clone $this;
249-
$obj->type = $type;
249+
$obj->type = $type instanceof Type ? $type->value : $type;
250250

251251
return $obj;
252252
}

src/Assets/AssetListParams/FileType.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,18 @@
44

55
namespace ImageKit\Assets\AssetListParams;
66

7-
use ImageKit\Core\Concerns\SdkEnum;
8-
use ImageKit\Core\Conversion\Contracts\ConverterSource;
9-
107
/**
118
* Filter results by file type.
129
*
1310
* - `all` — include all file types
1411
* - `image` — include only image files
1512
* - `non-image` — include only non-image files (e.g., JS, CSS, video)
1613
*/
17-
final class FileType implements ConverterSource
14+
enum FileType: string
1815
{
19-
use SdkEnum;
20-
21-
public const ALL = 'all';
16+
case ALL = 'all';
2217

23-
public const IMAGE = 'image';
18+
case IMAGE = 'image';
2419

25-
public const NON_IMAGE = 'non-image';
20+
case NON_IMAGE = 'non-image';
2621
}

src/Assets/AssetListParams/Sort.php

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,36 @@
44

55
namespace ImageKit\Assets\AssetListParams;
66

7-
use ImageKit\Core\Concerns\SdkEnum;
8-
use ImageKit\Core\Conversion\Contracts\ConverterSource;
9-
107
/**
118
* Sort the results by one of the supported fields in ascending or descending order.
129
*/
13-
final class Sort implements ConverterSource
10+
enum Sort: string
1411
{
15-
use SdkEnum;
16-
17-
public const ASC_NAME = 'ASC_NAME';
12+
case ASC_NAME = 'ASC_NAME';
1813

19-
public const DESC_NAME = 'DESC_NAME';
14+
case DESC_NAME = 'DESC_NAME';
2015

21-
public const ASC_CREATED = 'ASC_CREATED';
16+
case ASC_CREATED = 'ASC_CREATED';
2217

23-
public const DESC_CREATED = 'DESC_CREATED';
18+
case DESC_CREATED = 'DESC_CREATED';
2419

25-
public const ASC_UPDATED = 'ASC_UPDATED';
20+
case ASC_UPDATED = 'ASC_UPDATED';
2621

27-
public const DESC_UPDATED = 'DESC_UPDATED';
22+
case DESC_UPDATED = 'DESC_UPDATED';
2823

29-
public const ASC_HEIGHT = 'ASC_HEIGHT';
24+
case ASC_HEIGHT = 'ASC_HEIGHT';
3025

31-
public const DESC_HEIGHT = 'DESC_HEIGHT';
26+
case DESC_HEIGHT = 'DESC_HEIGHT';
3227

33-
public const ASC_WIDTH = 'ASC_WIDTH';
28+
case ASC_WIDTH = 'ASC_WIDTH';
3429

35-
public const DESC_WIDTH = 'DESC_WIDTH';
30+
case DESC_WIDTH = 'DESC_WIDTH';
3631

37-
public const ASC_SIZE = 'ASC_SIZE';
32+
case ASC_SIZE = 'ASC_SIZE';
3833

39-
public const DESC_SIZE = 'DESC_SIZE';
34+
case DESC_SIZE = 'DESC_SIZE';
4035

41-
public const ASC_RELEVANCE = 'ASC_RELEVANCE';
36+
case ASC_RELEVANCE = 'ASC_RELEVANCE';
4237

43-
public const DESC_RELEVANCE = 'DESC_RELEVANCE';
38+
case DESC_RELEVANCE = 'DESC_RELEVANCE';
4439
}

src/Assets/AssetListParams/Type.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
namespace ImageKit\Assets\AssetListParams;
66

7-
use ImageKit\Core\Concerns\SdkEnum;
8-
use ImageKit\Core\Conversion\Contracts\ConverterSource;
9-
107
/**
118
* Filter results by asset type.
129
*
@@ -15,15 +12,13 @@
1512
* - `folder` — returns only folders
1613
* - `all` — returns both files and folders (excludes `file-version`)
1714
*/
18-
final class Type implements ConverterSource
15+
enum Type: string
1916
{
20-
use SdkEnum;
21-
22-
public const FILE = 'file';
17+
case FILE = 'file';
2318

24-
public const FILE_VERSION = 'file-version';
19+
case FILE_VERSION = 'file-version';
2520

26-
public const FOLDER = 'folder';
21+
case FOLDER = 'folder';
2722

28-
public const ALL = 'all';
23+
case ALL = 'all';
2924
}

src/Beta/V2/Files/FileUploadParams.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
* overwriteCustomMetadata?: bool,
6161
* overwriteFile?: bool,
6262
* overwriteTags?: bool,
63-
* responseFields?: list<ResponseField::*>,
63+
* responseFields?: list<ResponseField|value-of<ResponseField>>,
6464
* tags?: list<string>,
6565
* transformation?: Transformation,
6666
* useUniqueFileName?: bool,
@@ -192,7 +192,7 @@ final class FileUploadParams implements BaseModel
192192
/**
193193
* Array of response field keys to include in the API response body.
194194
*
195-
* @var list<ResponseField::*>|null $responseFields
195+
* @var list<value-of<ResponseField>>|null $responseFields
196196
*/
197197
#[Api(list: ResponseField::class, optional: true)]
198198
public ?array $responseFields;
@@ -263,7 +263,7 @@ public function __construct()
263263
*
264264
* @param array<string, mixed> $customMetadata
265265
* @param list<RemoveBg|AutoTaggingExtension|AIAutoDescription> $extensions
266-
* @param list<ResponseField::*> $responseFields
266+
* @param list<ResponseField|value-of<ResponseField>> $responseFields
267267
* @param list<string> $tags
268268
*/
269269
public static function with(
@@ -306,7 +306,7 @@ public static function with(
306306
null !== $overwriteCustomMetadata && $obj->overwriteCustomMetadata = $overwriteCustomMetadata;
307307
null !== $overwriteFile && $obj->overwriteFile = $overwriteFile;
308308
null !== $overwriteTags && $obj->overwriteTags = $overwriteTags;
309-
null !== $responseFields && $obj->responseFields = $responseFields;
309+
null !== $responseFields && $obj->responseFields = array_map(fn ($v) => $v instanceof ResponseField ? $v->value : $v, $responseFields);
310310
null !== $tags && $obj->tags = $tags;
311311
null !== $transformation && $obj->transformation = $transformation;
312312
null !== $useUniqueFileName && $obj->useUniqueFileName = $useUniqueFileName;
@@ -510,12 +510,12 @@ public function withOverwriteTags(bool $overwriteTags): self
510510
/**
511511
* Array of response field keys to include in the API response body.
512512
*
513-
* @param list<ResponseField::*> $responseFields
513+
* @param list<ResponseField|value-of<ResponseField>> $responseFields
514514
*/
515515
public function withResponseFields(array $responseFields): self
516516
{
517517
$obj = clone $this;
518-
$obj->responseFields = $responseFields;
518+
$obj->responseFields = array_map(fn ($v) => $v instanceof ResponseField ? $v->value : $v, $responseFields);
519519

520520
return $obj;
521521
}

src/Beta/V2/Files/FileUploadParams/ResponseField.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,19 @@
44

55
namespace ImageKit\Beta\V2\Files\FileUploadParams;
66

7-
use ImageKit\Core\Concerns\SdkEnum;
8-
use ImageKit\Core\Conversion\Contracts\ConverterSource;
9-
10-
final class ResponseField implements ConverterSource
7+
enum ResponseField: string
118
{
12-
use SdkEnum;
13-
14-
public const TAGS = 'tags';
9+
case TAGS = 'tags';
1510

16-
public const CUSTOM_COORDINATES = 'customCoordinates';
11+
case CUSTOM_COORDINATES = 'customCoordinates';
1712

18-
public const IS_PRIVATE_FILE = 'isPrivateFile';
13+
case IS_PRIVATE_FILE = 'isPrivateFile';
1914

20-
public const EMBEDDED_METADATA = 'embeddedMetadata';
15+
case EMBEDDED_METADATA = 'embeddedMetadata';
2116

22-
public const IS_PUBLISHED = 'isPublished';
17+
case IS_PUBLISHED = 'isPublished';
2318

24-
public const CUSTOM_METADATA = 'customMetadata';
19+
case CUSTOM_METADATA = 'customMetadata';
2520

26-
public const METADATA = 'metadata';
21+
case METADATA = 'metadata';
2722
}

src/Beta/V2/Files/FileUploadParams/Transformation/Post/Abs.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
/**
1313
* @phpstan-type abs_alias = array{
14-
* protocol: Protocol::*, type: string, value: string
14+
* protocol: value-of<Protocol>, type: string, value: string
1515
* }
1616
*/
1717
final class Abs implements BaseModel
@@ -28,7 +28,7 @@ final class Abs implements BaseModel
2828
/**
2929
* Streaming protocol to use (`hls` or `dash`).
3030
*
31-
* @var Protocol::* $protocol
31+
* @var value-of<Protocol> $protocol
3232
*/
3333
#[Api(enum: Protocol::class)]
3434
public string $protocol;
@@ -63,13 +63,13 @@ public function __construct()
6363
*
6464
* You must use named parameters to construct any parameters with a default value.
6565
*
66-
* @param Protocol::* $protocol
66+
* @param Protocol|value-of<Protocol> $protocol
6767
*/
68-
public static function with(string $protocol, string $value): self
68+
public static function with(Protocol|string $protocol, string $value): self
6969
{
7070
$obj = new self;
7171

72-
$obj->protocol = $protocol;
72+
$obj->protocol = $protocol instanceof Protocol ? $protocol->value : $protocol;
7373
$obj->value = $value;
7474

7575
return $obj;
@@ -78,12 +78,12 @@ public static function with(string $protocol, string $value): self
7878
/**
7979
* Streaming protocol to use (`hls` or `dash`).
8080
*
81-
* @param Protocol::* $protocol
81+
* @param Protocol|value-of<Protocol> $protocol
8282
*/
83-
public function withProtocol(string $protocol): self
83+
public function withProtocol(Protocol|string $protocol): self
8484
{
8585
$obj = clone $this;
86-
$obj->protocol = $protocol;
86+
$obj->protocol = $protocol instanceof Protocol ? $protocol->value : $protocol;
8787

8888
return $obj;
8989
}

0 commit comments

Comments
 (0)