Remove old application API base transformer
This commit is contained in:
parent
cf500a1a54
commit
5c81f820d8
19 changed files with 101 additions and 468 deletions
|
@ -2,12 +2,11 @@
|
|||
|
||||
namespace Pterodactyl\Transformers\Api\Application;
|
||||
|
||||
use Pterodactyl\Models\Node;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Models\Allocation;
|
||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||
use Pterodactyl\Transformers\Api\Transformer;
|
||||
|
||||
class AllocationTransformer extends BaseTransformer
|
||||
class AllocationTransformer extends Transformer
|
||||
{
|
||||
/**
|
||||
* Relationships that can be loaded onto allocation transformations.
|
||||
|
@ -16,24 +15,12 @@ class AllocationTransformer extends BaseTransformer
|
|||
*/
|
||||
protected $availableIncludes = ['node', 'server'];
|
||||
|
||||
/**
|
||||
* Return the resource name for the JSONAPI output.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getResourceName(): string
|
||||
{
|
||||
return Allocation::RESOURCE_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a generic transformed allocation array.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Allocation $model
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function transform(Allocation $model)
|
||||
public function transform(Allocation $model): array
|
||||
{
|
||||
return [
|
||||
'id' => $model->id,
|
||||
|
@ -41,7 +28,7 @@ class AllocationTransformer extends BaseTransformer
|
|||
'alias' => $model->ip_alias,
|
||||
'port' => $model->port,
|
||||
'notes' => $model->notes,
|
||||
'assigned' => ! is_null($model->server_id),
|
||||
'assigned' => !is_null($model->server_id),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -51,18 +38,14 @@ class AllocationTransformer extends BaseTransformer
|
|||
* @param \Pterodactyl\Models\Allocation $allocation
|
||||
*
|
||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function includeNode(Allocation $allocation)
|
||||
{
|
||||
if (! $this->authorize(AdminAcl::RESOURCE_NODES)) {
|
||||
if (!$this->authorize(AdminAcl::RESOURCE_NODES)) {
|
||||
return $this->null();
|
||||
}
|
||||
|
||||
return $this->item(
|
||||
$allocation->node, $this->makeTransformer(NodeTransformer::class), Node::RESOURCE_NAME
|
||||
);
|
||||
return $this->item($allocation->node, new NodeTransformer());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -71,17 +54,13 @@ class AllocationTransformer extends BaseTransformer
|
|||
* @param \Pterodactyl\Models\Allocation $allocation
|
||||
*
|
||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function includeServer(Allocation $allocation)
|
||||
{
|
||||
if (! $this->authorize(AdminAcl::RESOURCE_SERVERS) || ! $allocation->server) {
|
||||
if (!$this->authorize(AdminAcl::RESOURCE_SERVERS) || !$allocation->server) {
|
||||
return $this->null();
|
||||
}
|
||||
|
||||
return $this->item(
|
||||
$allocation->server, $this->makeTransformer(ServerTransformer::class), Server::RESOURCE_NAME
|
||||
);
|
||||
return $this->item($allocation->server, new ServerTransformer());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue