Path: blob/1.0-develop/app/Transformers/Api/Application/DatabaseHostTransformer.php
10284 views
<?php12namespace Pterodactyl\Transformers\Api\Application;34use Pterodactyl\Models\Database;5use Pterodactyl\Models\DatabaseHost;6use League\Fractal\Resource\Collection;7use League\Fractal\Resource\NullResource;8use Pterodactyl\Services\Acl\Api\AdminAcl;910class DatabaseHostTransformer extends BaseTransformer11{12protected array $availableIncludes = [13'databases',14];1516/**17* Return the resource name for the JSONAPI output.18*/19public function getResourceName(): string20{21return DatabaseHost::RESOURCE_NAME;22}2324/**25* Transform database host into a representation for the application API.26*/27public function transform(DatabaseHost $model): array28{29return [30'id' => $model->id,31'name' => $model->name,32'host' => $model->host,33'port' => $model->port,34'username' => $model->username,35'node' => $model->node_id,36'created_at' => $model->created_at->toAtomString(),37'updated_at' => $model->updated_at->toAtomString(),38];39}4041/**42* Include the databases associated with this host.43*44* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException45*/46public function includeDatabases(DatabaseHost $model): Collection|NullResource47{48if (!$this->authorize(AdminAcl::RESOURCE_SERVER_DATABASES)) {49return $this->null();50}5152$model->loadMissing('databases');5354return $this->collection($model->getRelation('databases'), $this->makeTransformer(ServerDatabaseTransformer::class), Database::RESOURCE_NAME);55}56}575859