2020-10-31 18:14:28 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Resources\Wings;
|
|
|
|
|
|
|
|
use Pterodactyl\Models\Server;
|
|
|
|
use Illuminate\Container\Container;
|
|
|
|
use Illuminate\Http\Resources\Json\ResourceCollection;
|
|
|
|
use Pterodactyl\Services\Eggs\EggConfigurationService;
|
|
|
|
use Pterodactyl\Services\Servers\ServerConfigurationStructureService;
|
|
|
|
|
|
|
|
class ServerConfigurationCollection extends ResourceCollection
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Converts a collection of Server models into an array of configuration responses
|
|
|
|
* that can be understood by Wings. Make sure you've properly loaded the required
|
|
|
|
* relationships on the Server models before calling this function, otherwise you'll
|
2022-10-14 16:59:20 +00:00
|
|
|
* have some serious performance issues from all the N+1 queries.
|
2020-10-31 18:14:28 +00:00
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function toArray($request): array
|
2020-10-31 18:14:28 +00:00
|
|
|
{
|
|
|
|
$egg = Container::getInstance()->make(EggConfigurationService::class);
|
|
|
|
$configuration = Container::getInstance()->make(ServerConfigurationStructureService::class);
|
|
|
|
|
2021-01-23 20:09:16 +00:00
|
|
|
return $this->collection->map(function (Server $server) use ($configuration, $egg) {
|
2020-10-31 18:14:28 +00:00
|
|
|
return [
|
|
|
|
'uuid' => $server->uuid,
|
|
|
|
'settings' => $configuration->handle($server),
|
|
|
|
'process_configuration' => $egg->handle($server),
|
|
|
|
];
|
|
|
|
})->toArray();
|
|
|
|
}
|
|
|
|
}
|