forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPterodactylSerializer.php
More file actions
58 lines (50 loc) · 1.28 KB
/
PterodactylSerializer.php
File metadata and controls
58 lines (50 loc) · 1.28 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
<?php
namespace Pterodactyl\Extensions\League\Fractal\Serializers;
use League\Fractal\Serializer\ArraySerializer;
class PterodactylSerializer extends ArraySerializer
{
/**
* Serialize an item.
*/
public function item(?string $resourceKey, array $data): array
{
return [
'object' => $resourceKey,
'attributes' => $data,
];
}
/**
* Serialize a collection.
*/
public function collection(?string $resourceKey, array $data): array
{
$response = [];
foreach ($data as $datum) {
$response[] = $this->item($resourceKey, $datum);
}
return [
'object' => 'list',
'data' => $response,
];
}
/**
* Serialize a null resource.
*/
public function null(): ?array
{
return [
'object' => 'null_resource',
'attributes' => null,
];
}
/**
* Merge the included resources with the parent resource being serialized.
*/
public function mergeIncludes(array $transformedData, array $includedData): array
{
foreach ($includedData as $key => $datum) {
$transformedData['relationships'][$key] = $datum;
}
return $transformedData;
}
}