Path: blob/1.0-develop/app/Transformers/Api/Application/NestTransformer.php
10279 views
<?php12namespace Pterodactyl\Transformers\Api\Application;34use Pterodactyl\Models\Egg;5use Pterodactyl\Models\Nest;6use Pterodactyl\Models\Server;7use League\Fractal\Resource\Collection;8use League\Fractal\Resource\NullResource;9use Pterodactyl\Services\Acl\Api\AdminAcl;1011class NestTransformer extends BaseTransformer12{13/**14* Relationships that can be loaded onto this transformation.15*/16protected array $availableIncludes = [17'eggs', 'servers',18];1920/**21* Return the resource name for the JSONAPI output.22*/23public function getResourceName(): string24{25return Nest::RESOURCE_NAME;26}2728/**29* Transform a Nest model into a representation that can be consumed by the30* application API.31*/32public function transform(Nest $model): array33{34$response = $model->toArray();3536$response[$model->getUpdatedAtColumn()] = $this->formatTimestamp($model->updated_at);37$response[$model->getCreatedAtColumn()] = $this->formatTimestamp($model->created_at);3839return $response;40}4142/**43* Include the Eggs relationship on the given Nest model transformation.44*45* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException46*/47public function includeEggs(Nest $model): Collection|NullResource48{49if (!$this->authorize(AdminAcl::RESOURCE_EGGS)) {50return $this->null();51}5253$model->loadMissing('eggs');5455return $this->collection($model->getRelation('eggs'), $this->makeTransformer(EggTransformer::class), Egg::RESOURCE_NAME);56}5758/**59* Include the servers relationship on the given Nest model.60*61* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException62*/63public function includeServers(Nest $model): Collection|NullResource64{65if (!$this->authorize(AdminAcl::RESOURCE_SERVERS)) {66return $this->null();67}6869$model->loadMissing('servers');7071return $this->collection($model->getRelation('servers'), $this->makeTransformer(ServerTransformer::class), Server::RESOURCE_NAME);72}73}747576