mirror of
				https://github.com/pelican-dev/panel.git
				synced 2025-11-04 03:36:53 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			58 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			58 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
namespace App\Transformers\Api\Application;
 | 
						|
 | 
						|
use App\Models\Database;
 | 
						|
use App\Models\DatabaseHost;
 | 
						|
use League\Fractal\Resource\Collection;
 | 
						|
use League\Fractal\Resource\NullResource;
 | 
						|
use App\Services\Acl\Api\AdminAcl;
 | 
						|
 | 
						|
class DatabaseHostTransformer extends BaseTransformer
 | 
						|
{
 | 
						|
    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,
 | 
						|
            'node' => $model->node_id,
 | 
						|
            'created_at' => $model->created_at->toAtomString(),
 | 
						|
            'updated_at' => $model->updated_at->toAtomString(),
 | 
						|
        ];
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Include the databases associated with this host.
 | 
						|
     *
 | 
						|
     * @throws \App\Exceptions\Transformer\InvalidTransformerLevelException
 | 
						|
     */
 | 
						|
    public function includeDatabases(DatabaseHost $model): Collection|NullResource
 | 
						|
    {
 | 
						|
        if (!$this->authorize(AdminAcl::RESOURCE_SERVER_DATABASES)) {
 | 
						|
            return $this->null();
 | 
						|
        }
 | 
						|
 | 
						|
        $model->loadMissing('databases');
 | 
						|
 | 
						|
        return $this->collection($model->getRelation('databases'), $this->makeTransformer(ServerDatabaseTransformer::class), Database::RESOURCE_NAME);
 | 
						|
    }
 | 
						|
}
 |