Files
pterodactyl-panel/app/Http/Resources/Wings/ServerConfigurationCollection.php
T

51 lines
1.8 KiB
PHP
Raw 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 Pterodactyl\Support\JsonValueGuard;
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
*
* @return array<array-key, array{uuid: string, settings: array<string, JsonValue>, process_configuration: array<string, JsonValue>}>
*/
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.');
$processConfiguration = $this->egg->handle($server);
JsonValueGuard::assertPayload9($processConfiguration);
2026-10-05 18:10:18 -04:00
$result[] = [
'uuid' => $server->uuid,
2026-10-05 18:10:18 -04:00
'settings' => $this->configuration->handle($server),
'process_configuration' => $processConfiguration,
];
2026-10-05 18:10:18 -04:00
}
return $result;
}
}