Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Http/Resources/Wings/ServerConfigurationCollection.php
10266 views
1
<?php
2
3
namespace Pterodactyl\Http\Resources\Wings;
4
5
use Pterodactyl\Models\Server;
6
use Illuminate\Container\Container;
7
use Illuminate\Http\Resources\Json\ResourceCollection;
8
use Pterodactyl\Services\Eggs\EggConfigurationService;
9
use Pterodactyl\Services\Servers\ServerConfigurationStructureService;
10
11
class ServerConfigurationCollection extends ResourceCollection
12
{
13
/**
14
* Converts a collection of Server models into an array of configuration responses
15
* that can be understood by Wings. Make sure you've properly loaded the required
16
* relationships on the Server models before calling this function, otherwise you'll
17
* have some serious performance issues from all the N+1 queries.
18
*/
19
public function toArray($request): array
20
{
21
$egg = Container::getInstance()->make(EggConfigurationService::class);
22
$configuration = Container::getInstance()->make(ServerConfigurationStructureService::class);
23
24
return $this->collection->map(function (Server $server) use ($configuration, $egg) {
25
return [
26
'uuid' => $server->uuid,
27
'settings' => $configuration->handle($server),
28
'process_configuration' => $egg->handle($server),
29
];
30
})->toArray();
31
}
32
}
33
34