pelican-panel-mirror/app/Transformers/Api/Application/ServerDatabaseTransformer.php
Lance Pioch da195fd2fe
PHPstan updates (#1047)
* Not found property rule

* Make these “better”

* Day 1

* Day 2

* Day 3

* Dat 4

* Remove disabled check

* Day 4 continued

* Run pint

* Final changes hopefully

* Pint fixes

* Fix again

* Reset these

* Update app/Filament/Admin/Pages/Health.php

Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com>

* Update app/Traits/CheckMigrationsTrait.php

Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com>

---------

Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com>
2025-03-03 14:41:19 -05:00

70 lines
1.8 KiB
PHP

<?php
namespace App\Transformers\Api\Application;
use App\Models\Database;
use League\Fractal\Resource\Item;
use App\Models\DatabaseHost;
use League\Fractal\Resource\NullResource;
class ServerDatabaseTransformer extends BaseTransformer
{
protected array $availableIncludes = ['password', 'host'];
/**
* Return the resource name for the JSONAPI output.
*/
public function getResourceName(): string
{
return Database::RESOURCE_NAME;
}
/**
* @param Database $model
*/
public function transform($model): array
{
return [
'id' => $model->id,
'server' => $model->server_id,
'host' => $model->database_host_id,
'database' => $model->database,
'username' => $model->username,
'remote' => $model->remote,
'max_connections' => $model->max_connections,
'created_at' => $model->created_at->toAtomString(),
'updated_at' => $model->updated_at->toAtomString(),
];
}
/**
* Include the database password in the request.
*/
public function includePassword(Database $model): Item
{
return $this->item($model, function (Database $model) {
return [
'password' => $model->password,
];
}, 'database_password');
}
/**
* Return the database host relationship for this server database.
*/
public function includeHost(Database $model): Item|NullResource
{
if (!$this->authorize(DatabaseHost::RESOURCE_NAME)) {
return $this->null();
}
$model->loadMissing('host');
return $this->item(
$model->getRelation('host'),
$this->makeTransformer(DatabaseHostTransformer::class),
DatabaseHost::RESOURCE_NAME
);
}
}