Path: blob/1.0-develop/app/Transformers/Api/Application/LocationTransformer.php
10279 views
<?php12namespace Pterodactyl\Transformers\Api\Application;34use Pterodactyl\Models\Location;5use League\Fractal\Resource\Collection;6use League\Fractal\Resource\NullResource;7use Pterodactyl\Services\Acl\Api\AdminAcl;89class LocationTransformer extends BaseTransformer10{11/**12* List of resources that can be included.13*/14protected array $availableIncludes = ['nodes', 'servers'];1516/**17* Return the resource name for the JSONAPI output.18*/19public function getResourceName(): string20{21return Location::RESOURCE_NAME;22}2324/**25* Return a generic transformed location array.26*/27public function transform(Location $location): array28{29return [30'id' => $location->id,31'short' => $location->short,32'long' => $location->long,33$location->getUpdatedAtColumn() => $this->formatTimestamp($location->updated_at),34$location->getCreatedAtColumn() => $this->formatTimestamp($location->created_at),35];36}3738/**39* Return the nodes associated with this location.40*41* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException42*/43public function includeServers(Location $location): Collection|NullResource44{45if (!$this->authorize(AdminAcl::RESOURCE_SERVERS)) {46return $this->null();47}4849$location->loadMissing('servers');5051return $this->collection($location->getRelation('servers'), $this->makeTransformer(ServerTransformer::class), 'server');52}5354/**55* Return the nodes associated with this location.56*57* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException58*/59public function includeNodes(Location $location): Collection|NullResource60{61if (!$this->authorize(AdminAcl::RESOURCE_NODES)) {62return $this->null();63}6465$location->loadMissing('nodes');6667return $this->collection($location->getRelation('nodes'), $this->makeTransformer(NodeTransformer::class), 'node');68}69}707172