2020-10-31 11:14:28 -07:00
|
|
|
<?php
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2020-10-31 11:14:28 -07:00
|
|
|
namespace Pterodactyl\Http\Resources\Wings;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Http\Resources\Json\ResourceCollection;
|
2026-10-05 18:10:18 -04:00
|
|
|
use Pterodactyl\Models\Server;
|
2020-10-31 11:14:28 -07:00
|
|
|
use Pterodactyl\Services\Eggs\EggConfigurationService;
|
|
|
|
|
use Pterodactyl\Services\Servers\ServerConfigurationStructureService;
|
2026-10-05 18:10:18 -04:00
|
|
|
use UnexpectedValueException;
|
2020-10-31 11:14:28 -07:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-31 11:14:28 -07:00
|
|
|
/**
|
|
|
|
|
* 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>}>
|
2020-10-31 11:14:28 -07:00
|
|
|
*/
|
2022-10-14 10:59:20 -06:00
|
|
|
public function toArray($request): array
|
2020-10-31 11:14:28 -07:00
|
|
|
{
|
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);
|
2020-10-31 11:14:28 -07:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
$result[] = [
|
2020-10-31 11:14:28 -07:00
|
|
|
'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,
|
2020-10-31 11:14:28 -07:00
|
|
|
];
|
2026-10-05 18:10:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $result;
|
2020-10-31 11:14:28 -07:00
|
|
|
}
|
|
|
|
|
}
|