misc_pterodactyl-panel/app/Extensions/League/Fractal/Serializers/PterodactylSerializer.php

59 lines
1.3 KiB
PHP
Raw Permalink Normal View History

<?php
namespace Pterodactyl\Extensions\League\Fractal\Serializers;
use League\Fractal\Serializer\ArraySerializer;
class PterodactylSerializer extends ArraySerializer
{
/**
* Serialize an item.
*/
2022-05-04 23:35:10 +00:00
public function item(?string $resourceKey, array $data): array
{
return [
'object' => $resourceKey,
'attributes' => $data,
];
}
/**
* Serialize a collection.
*/
2022-05-04 23:35:10 +00:00
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.
*/
2022-05-04 23:35:10 +00:00
public function null(): ?array
{
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
{
foreach ($includedData as $key => $datum) {
$transformedData['relationships'][$key] = $datum;
}
return $transformedData;
}
}