Files

49 lines
1.7 KiB
PHP
Raw Permalink Normal View History

<?php
2026-10-05 18:10:18 -04:00
declare(strict_types=1);
namespace Pterodactyl\Http\Resources\Wings;
use Illuminate\Http\Resources\Json\ResourceCollection;
2026-10-05 18:10:18 -04:00
use Pterodactyl\Models\Server;
use Pterodactyl\Services\Eggs\EggConfigurationService;
use Pterodactyl\Services\Servers\ServerConfigurationStructureService;
2026-10-05 18:10:18 -04:00
use UnexpectedValueException;
class ServerConfigurationCollection extends ResourceCollection
{
2026-10-05 18:10:18 -04:00
public function __construct(
mixed $resource,
private readonly EggConfigurationService $egg,
private readonly ServerConfigurationStructureService $configuration,
) {
parent::__construct($resource);
}
/**
* 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 10:59:20 -06:00
* have some serious performance issues from all the N+1 queries.
2026-10-05 18:10:18 -04:00
*
2026-10-11 19:54:55 -04:00
* @return array<array-key, array{uuid: string, settings: array<string, mixed>, process_configuration: array<string, mixed>}>
*/
2022-10-14 10:59:20 -06:00
public function toArray($request): array
{
2026-10-05 18:10:18 -04:00
$result = [];
foreach ($this->collection ?? [] as $server) {
throw_unless($server instanceof Server, UnexpectedValueException::class, 'Server configuration resources require Server models.');
2026-10-12 00:25:54 -04:00
$processConfiguration = $this->egg->forServer($server);
2026-10-05 18:10:18 -04:00
$result[] = [
'uuid' => $server->uuid,
2026-10-12 00:21:31 -04:00
'settings' => $this->configuration->forServer($server),
2026-10-05 18:10:18 -04:00
'process_configuration' => $processConfiguration,
];
2026-10-05 18:10:18 -04:00
}
return $result;
}
}