Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Extensions/League/Fractal/Serializers/PterodactylSerializer.php
7461 views
1
<?php
2
3
namespace Pterodactyl\Extensions\League\Fractal\Serializers;
4
5
use League\Fractal\Serializer\ArraySerializer;
6
7
class PterodactylSerializer extends ArraySerializer
8
{
9
/**
10
* Serialize an item.
11
*/
12
public function item(?string $resourceKey, array $data): array
13
{
14
return [
15
'object' => $resourceKey,
16
'attributes' => $data,
17
];
18
}
19
20
/**
21
* Serialize a collection.
22
*/
23
public function collection(?string $resourceKey, array $data): array
24
{
25
$response = [];
26
foreach ($data as $datum) {
27
$response[] = $this->item($resourceKey, $datum);
28
}
29
30
return [
31
'object' => 'list',
32
'data' => $response,
33
];
34
}
35
36
/**
37
* Serialize a null resource.
38
*/
39
public function null(): ?array
40
{
41
return [
42
'object' => 'null_resource',
43
'attributes' => null,
44
];
45
}
46
47
/**
48
* Merge the included resources with the parent resource being serialized.
49
*/
50
public function mergeIncludes(array $transformedData, array $includedData): array
51
{
52
foreach ($includedData as $key => $datum) {
53
$transformedData['relationships'][$key] = $datum;
54
}
55
56
return $transformedData;
57
}
58
}
59
60