2018-01-27 18:38:56 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Extensions\League\Fractal\Serializers;
|
|
|
|
|
|
|
|
use League\Fractal\Serializer\ArraySerializer;
|
|
|
|
|
|
|
|
class PterodactylSerializer extends ArraySerializer
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Serialize a collection.
|
|
|
|
*/
|
2022-05-04 23:35:10 +00:00
|
|
|
public function collection(?string $resourceKey, array $data): array
|
2018-01-27 18:38:56 +00:00
|
|
|
{
|
|
|
|
$response = [];
|
|
|
|
foreach ($data as $datum) {
|
|
|
|
$response[] = $this->item($resourceKey, $datum);
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
'object' => 'list',
|
|
|
|
'data' => $response,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2022-12-15 02:13:00 +00:00
|
|
|
/**
|
|
|
|
* Serialize an item.
|
|
|
|
*/
|
|
|
|
public function item(?string $resourceKey, array $data): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'object' => $resourceKey,
|
|
|
|
'attributes' => $data,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2018-01-27 18:38:56 +00:00
|
|
|
/**
|
|
|
|
* Serialize a null resource.
|
|
|
|
*/
|
2022-05-04 23:35:10 +00:00
|
|
|
public function null(): ?array
|
2018-01-27 18:38:56 +00:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
'object' => 'null_resource',
|
|
|
|
'attributes' => null,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Merge the included resources with the parent resource being serialized.
|
|
|
|
*/
|
2022-05-04 23:35:10 +00:00
|
|
|
public function mergeIncludes(array $transformedData, array $includedData): array
|
2018-01-27 18:38:56 +00:00
|
|
|
{
|
|
|
|
foreach ($includedData as $key => $datum) {
|
|
|
|
$transformedData['relationships'][$key] = $datum;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $transformedData;
|
|
|
|
}
|
|
|
|
}
|