58 lines
1.3 KiB
PHP
58 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Pterodactyl\Extensions\League\Fractal\Serializers;
|
|
|
|
use League\Fractal\Serializer\ArraySerializer;
|
|
|
|
class PterodactylSerializer extends ArraySerializer
|
|
{
|
|
/**
|
|
* 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 an item.
|
|
*/
|
|
public function item(?string $resourceKey, array $data): array
|
|
{
|
|
return [
|
|
'object' => $resourceKey,
|
|
'attributes' => $data,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
}
|
|
}
|