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

51 lines
1.3 KiB
PHP
Raw Normal View History

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