-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathFile.php
More file actions
138 lines (131 loc) Β· 5.94 KB
/
Copy pathFile.php
File metadata and controls
138 lines (131 loc) Β· 5.94 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
namespace Appwrite\Models;
/**
* File
*/
readonly class File
{
use ArraySerializable;
/**
* File constructor.
*
* @param string $id file id.
* @param string $bucketId bucket id.
* @param string $createdAt file creation date in iso 8601 format.
* @param string $updatedAt file update date in iso 8601 format.
* @param array $permissions file permissions. [learn more about permissions](https://appwrite.io/docs/permissions).
* @param string $name file name.
* @param string $signature file md5 signature.
* @param string $mimeType file mime type.
* @param int $sizeOriginal file original size in bytes.
* @param int $sizeActual file actual stored size in bytes after compression and/or encryption.
* @param int $chunksTotal total number of chunks available
* @param int $chunksUploaded total number of chunks uploaded
* @param bool $encryption whether file contents are encrypted at rest.
* @param string $compression compression algorithm used for the file. will be one of none, [gzip](https://en.wikipedia.org/wiki/gzip), or [zstd](https://en.wikipedia.org/wiki/zstd).
*/
public function __construct(
public string $id,
public string $bucketId,
public string $createdAt,
public string $updatedAt,
public array $permissions,
public string $name,
public string $signature,
public string $mimeType,
public int $sizeOriginal,
public int $sizeActual,
public int $chunksTotal,
public int $chunksUploaded,
public bool $encryption,
public string $compression
) {
}
/**
* @param array<string, mixed> $data
*/
public static function from(array $data): static
{
if (!array_key_exists('$id', $data)) {
throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.');
}
if (!array_key_exists('bucketId', $data)) {
throw new \InvalidArgumentException('Missing required field "bucketId" for ' . static::class . '.');
}
if (!array_key_exists('$createdAt', $data)) {
throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.');
}
if (!array_key_exists('$updatedAt', $data)) {
throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.');
}
if (!array_key_exists('$permissions', $data)) {
throw new \InvalidArgumentException('Missing required field "$permissions" for ' . static::class . '.');
}
if (!array_key_exists('name', $data)) {
throw new \InvalidArgumentException('Missing required field "name" for ' . static::class . '.');
}
if (!array_key_exists('signature', $data)) {
throw new \InvalidArgumentException('Missing required field "signature" for ' . static::class . '.');
}
if (!array_key_exists('mimeType', $data)) {
throw new \InvalidArgumentException('Missing required field "mimeType" for ' . static::class . '.');
}
if (!array_key_exists('sizeOriginal', $data)) {
throw new \InvalidArgumentException('Missing required field "sizeOriginal" for ' . static::class . '.');
}
if (!array_key_exists('sizeActual', $data)) {
throw new \InvalidArgumentException('Missing required field "sizeActual" for ' . static::class . '.');
}
if (!array_key_exists('chunksTotal', $data)) {
throw new \InvalidArgumentException('Missing required field "chunksTotal" for ' . static::class . '.');
}
if (!array_key_exists('chunksUploaded', $data)) {
throw new \InvalidArgumentException('Missing required field "chunksUploaded" for ' . static::class . '.');
}
if (!array_key_exists('encryption', $data)) {
throw new \InvalidArgumentException('Missing required field "encryption" for ' . static::class . '.');
}
if (!array_key_exists('compression', $data)) {
throw new \InvalidArgumentException('Missing required field "compression" for ' . static::class . '.');
}
return new static(
id: $data['$id'],
bucketId: $data['bucketId'],
createdAt: $data['$createdAt'],
updatedAt: $data['$updatedAt'],
permissions: $data['$permissions'],
name: $data['name'],
signature: $data['signature'],
mimeType: $data['mimeType'],
sizeOriginal: $data['sizeOriginal'],
sizeActual: $data['sizeActual'],
chunksTotal: $data['chunksTotal'],
chunksUploaded: $data['chunksUploaded'],
encryption: $data['encryption'],
compression: $data['compression']
);
}
/**
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [
'$id' => static::serializeValue($this->id),
'bucketId' => static::serializeValue($this->bucketId),
'$createdAt' => static::serializeValue($this->createdAt),
'$updatedAt' => static::serializeValue($this->updatedAt),
'$permissions' => static::serializeValue($this->permissions),
'name' => static::serializeValue($this->name),
'signature' => static::serializeValue($this->signature),
'mimeType' => static::serializeValue($this->mimeType),
'sizeOriginal' => static::serializeValue($this->sizeOriginal),
'sizeActual' => static::serializeValue($this->sizeActual),
'chunksTotal' => static::serializeValue($this->chunksTotal),
'chunksUploaded' => static::serializeValue($this->chunksUploaded),
'encryption' => static::serializeValue($this->encryption),
'compression' => static::serializeValue($this->compression)
];
return $result;
}
}