misc_pterodactyl-panel/app/Transformers/Api/Application/DatabaseHostTransformer.php

53 lines
1.5 KiB
PHP
Raw Normal View History

<?php
namespace Pterodactyl\Transformers\Api\Application;
use Pterodactyl\Models\DatabaseHost;
use League\Fractal\Resource\Collection;
use League\Fractal\Resource\NullResource;
use Pterodactyl\Services\Acl\Api\AdminAcl;
2022-12-15 00:05:46 +00:00
use Pterodactyl\Transformers\Api\Transformer;
2022-12-15 00:05:46 +00:00
class DatabaseHostTransformer extends Transformer
{
2022-12-15 00:05:46 +00:00
protected array $availableIncludes = ['databases'];
/**
* Return the resource name for the JSONAPI output.
*/
public function getResourceName(): string
{
return DatabaseHost::RESOURCE_NAME;
}
/**
* Transform database host into a representation for the application API.
*/
public function transform(DatabaseHost $model): array
{
return [
'id' => $model->id,
'name' => $model->name,
'host' => $model->host,
'port' => $model->port,
'username' => $model->username,
2022-12-15 00:05:46 +00:00
'node_id' => $model->node_id,
'created_at' => self::formatTimestamp($model->created_at),
'updated_at' => self::formatTimestamp($model->updated_at),
];
}
/**
* Include the databases associated with this host.
*/
public function includeDatabases(DatabaseHost $model): Collection|NullResource
{
2021-01-23 20:33:34 +00:00
if (!$this->authorize(AdminAcl::RESOURCE_SERVER_DATABASES)) {
return $this->null();
}
2022-12-15 00:05:46 +00:00
// TODO
return $this->collection($model->databases, new ServerDatabaseTransformer());
}
}