misc_pterodactyl-panel/app/Transformers/Api/Application/MountTransformer.php
2021-08-07 13:25:06 -07:00

78 lines
2.1 KiB
PHP

<?php
namespace Pterodactyl\Transformers\Api\Application;
use Pterodactyl\Models\Mount;
use Pterodactyl\Services\Acl\Api\AdminAcl;
use Pterodactyl\Transformers\Api\Transformer;
class MountTransformer extends Transformer
{
/**
* List of resources that can be included.
*
* @var array
*/
protected $availableIncludes = ['eggs', 'nodes', 'servers'];
public function getResourceName(): string
{
return Mount::RESOURCE_NAME;
}
public function transform(Mount $model): array
{
return [
'id' => $model->id,
'uuid' => $model->uuid,
'name' => $model->name,
'description' => $model->description,
'source' => $model->source,
'target' => $model->target,
'read_only' => $model->read_only,
'user_mountable' => $model->user_mountable,
];
}
/**
* Return the eggs associated with this mount.
*
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
*/
public function includeEggs(Mount $mount)
{
if (!$this->authorize(AdminAcl::RESOURCE_EGGS)) {
return $this->null();
}
return $this->collection($mount->eggs, new EggTransformer());
}
/**
* Return the nodes associated with this mount.
*
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
*/
public function includeNodes(Mount $mount)
{
if (!$this->authorize(AdminAcl::RESOURCE_NODES)) {
return $this->null();
}
return $this->collection($mount->nodes, new NodeTransformer());
}
/**
* Return the servers associated with this mount.
*
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
*/
public function includeServers(Mount $mount)
{
if (!$this->authorize(AdminAcl::RESOURCE_SERVERS)) {
return $this->null();
}
return $this->collection($mount->servers, new ServerTransformer());
}
}