Remove unnecessary function

This commit is contained in:
Dane Everitt 2021-08-07 14:32:40 -07:00
parent bbf2f33c5e
commit fdd90b3be7
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
37 changed files with 92 additions and 136 deletions

View file

@ -44,20 +44,6 @@ abstract class ApplicationApiController extends Controller
$this->request = $request; $this->request = $request;
} }
/**
* Return an instance of an application transformer.
*
* @return \Pterodactyl\Transformers\Api\Transformer
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*
* @deprecated
*/
public function getTransformer(string $abstract)
{
return new $abstract;
}
/** /**
* Return a HTTP/201 response for the API. * Return a HTTP/201 response for the API.
*/ */

View file

@ -51,7 +51,7 @@ class DatabaseController extends ApplicationApiController
->paginate($perPage); ->paginate($perPage);
return $this->fractal->collection($databases) return $this->fractal->collection($databases)
->transformWith($this->getTransformer(DatabaseHostTransformer::class)) ->transformWith(DatabaseHostTransformer::class)
->toArray(); ->toArray();
} }
@ -63,7 +63,7 @@ class DatabaseController extends ApplicationApiController
public function view(GetDatabaseRequest $request, DatabaseHost $databaseHost): array public function view(GetDatabaseRequest $request, DatabaseHost $databaseHost): array
{ {
return $this->fractal->item($databaseHost) return $this->fractal->item($databaseHost)
->transformWith($this->getTransformer(DatabaseHostTransformer::class)) ->transformWith(DatabaseHostTransformer::class)
->toArray(); ->toArray();
} }
@ -77,7 +77,7 @@ class DatabaseController extends ApplicationApiController
$databaseHost = $this->creationService->handle($request->validated()); $databaseHost = $this->creationService->handle($request->validated());
return $this->fractal->item($databaseHost) return $this->fractal->item($databaseHost)
->transformWith($this->getTransformer(DatabaseHostTransformer::class)) ->transformWith(DatabaseHostTransformer::class)
->respond(JsonResponse::HTTP_CREATED); ->respond(JsonResponse::HTTP_CREATED);
} }
@ -91,7 +91,7 @@ class DatabaseController extends ApplicationApiController
$databaseHost = $this->updateService->handle($databaseHost->id, $request->validated()); $databaseHost = $this->updateService->handle($databaseHost->id, $request->validated());
return $this->fractal->item($databaseHost) return $this->fractal->item($databaseHost)
->transformWith($this->getTransformer(DatabaseHostTransformer::class)) ->transformWith(DatabaseHostTransformer::class)
->toArray(); ->toArray();
} }

View file

@ -52,7 +52,7 @@ class EggController extends ApplicationApiController
} }
return $this->fractal->collection($eggs) return $this->fractal->collection($eggs)
->transformWith($this->getTransformer(EggTransformer::class)) ->transformWith(EggTransformer::class)
->toArray(); ->toArray();
} }
@ -64,7 +64,7 @@ class EggController extends ApplicationApiController
public function view(GetEggRequest $request, Egg $egg): array public function view(GetEggRequest $request, Egg $egg): array
{ {
return $this->fractal->item($egg) return $this->fractal->item($egg)
->transformWith($this->getTransformer(EggTransformer::class)) ->transformWith(EggTransformer::class)
->toArray(); ->toArray();
} }
@ -78,7 +78,7 @@ class EggController extends ApplicationApiController
$egg = Egg::query()->create($request->validated()); $egg = Egg::query()->create($request->validated());
return $this->fractal->item($egg) return $this->fractal->item($egg)
->transformWith($this->getTransformer(EggTransformer::class)) ->transformWith(EggTransformer::class)
->respond(JsonResponse::HTTP_CREATED); ->respond(JsonResponse::HTTP_CREATED);
} }
@ -92,7 +92,7 @@ class EggController extends ApplicationApiController
$egg->update($request->validated()); $egg->update($request->validated());
return $this->fractal->item($egg) return $this->fractal->item($egg)
->transformWith($this->getTransformer(EggTransformer::class)) ->transformWith(EggTransformer::class)
->toArray(); ->toArray();
} }

View file

@ -57,7 +57,7 @@ class LocationController extends ApplicationApiController
->paginate($perPage); ->paginate($perPage);
return $this->fractal->collection($locations) return $this->fractal->collection($locations)
->transformWith($this->getTransformer(LocationTransformer::class)) ->transformWith(LocationTransformer::class)
->toArray(); ->toArray();
} }
@ -69,7 +69,7 @@ class LocationController extends ApplicationApiController
public function view(GetLocationRequest $request, Location $location): array public function view(GetLocationRequest $request, Location $location): array
{ {
return $this->fractal->item($location) return $this->fractal->item($location)
->transformWith($this->getTransformer(LocationTransformer::class)) ->transformWith(LocationTransformer::class)
->toArray(); ->toArray();
} }
@ -85,7 +85,7 @@ class LocationController extends ApplicationApiController
$location = $this->creationService->handle($request->validated()); $location = $this->creationService->handle($request->validated());
return $this->fractal->item($location) return $this->fractal->item($location)
->transformWith($this->getTransformer(LocationTransformer::class)) ->transformWith(LocationTransformer::class)
->addMeta([ ->addMeta([
'resource' => route('api.application.locations.view', [ 'resource' => route('api.application.locations.view', [
'location' => $location->id, 'location' => $location->id,
@ -106,7 +106,7 @@ class LocationController extends ApplicationApiController
$location = $this->updateService->handle($location, $request->validated()); $location = $this->updateService->handle($location, $request->validated());
return $this->fractal->item($location) return $this->fractal->item($location)
->transformWith($this->getTransformer(LocationTransformer::class)) ->transformWith(LocationTransformer::class)
->toArray(); ->toArray();
} }

View file

@ -45,7 +45,7 @@ class MountController extends ApplicationApiController
->paginate($perPage); ->paginate($perPage);
return $this->fractal->collection($mounts) return $this->fractal->collection($mounts)
->transformWith($this->getTransformer(MountTransformer::class)) ->transformWith(MountTransformer::class)
->toArray(); ->toArray();
} }
@ -57,7 +57,7 @@ class MountController extends ApplicationApiController
public function view(GetMountRequest $request, Mount $mount): array public function view(GetMountRequest $request, Mount $mount): array
{ {
return $this->fractal->item($mount) return $this->fractal->item($mount)
->transformWith($this->getTransformer(MountTransformer::class)) ->transformWith(MountTransformer::class)
->toArray(); ->toArray();
} }
@ -71,7 +71,7 @@ class MountController extends ApplicationApiController
$mount = Mount::query()->create($request->validated()); $mount = Mount::query()->create($request->validated());
return $this->fractal->item($mount) return $this->fractal->item($mount)
->transformWith($this->getTransformer(MountTransformer::class)) ->transformWith(MountTransformer::class)
->respond(JsonResponse::HTTP_CREATED); ->respond(JsonResponse::HTTP_CREATED);
} }
@ -85,7 +85,7 @@ class MountController extends ApplicationApiController
$mount->update($request->validated()); $mount->update($request->validated());
return $this->fractal->item($mount) return $this->fractal->item($mount)
->transformWith($this->getTransformer(MountTransformer::class)) ->transformWith(MountTransformer::class)
->toArray(); ->toArray();
} }
@ -116,7 +116,7 @@ class MountController extends ApplicationApiController
} }
return $this->fractal->item($mount) return $this->fractal->item($mount)
->transformWith($this->getTransformer(MountTransformer::class)) ->transformWith(MountTransformer::class)
->toArray(); ->toArray();
} }
@ -135,7 +135,7 @@ class MountController extends ApplicationApiController
} }
return $this->fractal->item($mount) return $this->fractal->item($mount)
->transformWith($this->getTransformer(MountTransformer::class)) ->transformWith(MountTransformer::class)
->toArray(); ->toArray();
} }
@ -154,7 +154,7 @@ class MountController extends ApplicationApiController
} }
return $this->fractal->item($mount) return $this->fractal->item($mount)
->transformWith($this->getTransformer(MountTransformer::class)) ->transformWith(MountTransformer::class)
->toArray(); ->toArray();
} }
@ -173,7 +173,7 @@ class MountController extends ApplicationApiController
} }
return $this->fractal->item($mount) return $this->fractal->item($mount)
->transformWith($this->getTransformer(MountTransformer::class)) ->transformWith(MountTransformer::class)
->toArray(); ->toArray();
} }
} }

View file

@ -63,7 +63,7 @@ class NestController extends ApplicationApiController
} }
return $this->fractal->collection($nests) return $this->fractal->collection($nests)
->transformWith($this->getTransformer(NestTransformer::class)) ->transformWith(NestTransformer::class)
->toArray(); ->toArray();
} }
@ -75,7 +75,7 @@ class NestController extends ApplicationApiController
public function view(GetNestRequest $request, Nest $nest): array public function view(GetNestRequest $request, Nest $nest): array
{ {
return $this->fractal->item($nest) return $this->fractal->item($nest)
->transformWith($this->getTransformer(NestTransformer::class)) ->transformWith(NestTransformer::class)
->toArray(); ->toArray();
} }
@ -90,7 +90,7 @@ class NestController extends ApplicationApiController
$nest = $this->nestCreationService->handle($request->validated()); $nest = $this->nestCreationService->handle($request->validated());
return $this->fractal->item($nest) return $this->fractal->item($nest)
->transformWith($this->getTransformer(NestTransformer::class)) ->transformWith(NestTransformer::class)
->toArray(); ->toArray();
} }
@ -106,7 +106,7 @@ class NestController extends ApplicationApiController
$this->nestUpdateService->handle($nest->id, $request->validated()); $this->nestUpdateService->handle($nest->id, $request->validated());
return $this->fractal->item($nest) return $this->fractal->item($nest)
->transformWith($this->getTransformer(NestTransformer::class)) ->transformWith(NestTransformer::class)
->toArray(); ->toArray();
} }

View file

@ -47,7 +47,7 @@ class AllocationController extends ApplicationApiController
$allocations = $node->allocations()->paginate($perPage); $allocations = $node->allocations()->paginate($perPage);
return $this->fractal->collection($allocations) return $this->fractal->collection($allocations)
->transformWith($this->getTransformer(AllocationTransformer::class)) ->transformWith(AllocationTransformer::class)
->toArray(); ->toArray();
} }

View file

@ -61,7 +61,7 @@ class NodeController extends ApplicationApiController
->paginate($perPage); ->paginate($perPage);
return $this->fractal->collection($nodes) return $this->fractal->collection($nodes)
->transformWith($this->getTransformer(NodeTransformer::class)) ->transformWith(NodeTransformer::class)
->toArray(); ->toArray();
} }
@ -73,7 +73,7 @@ class NodeController extends ApplicationApiController
public function view(GetNodeRequest $request, Node $node): array public function view(GetNodeRequest $request, Node $node): array
{ {
return $this->fractal->item($node) return $this->fractal->item($node)
->transformWith($this->getTransformer(NodeTransformer::class)) ->transformWith(NodeTransformer::class)
->toArray(); ->toArray();
} }
@ -89,7 +89,7 @@ class NodeController extends ApplicationApiController
$node = $this->creationService->handle($request->validated()); $node = $this->creationService->handle($request->validated());
return $this->fractal->item($node) return $this->fractal->item($node)
->transformWith($this->getTransformer(NodeTransformer::class)) ->transformWith(NodeTransformer::class)
->addMeta([ ->addMeta([
'resource' => route('api.application.nodes.view', [ 'resource' => route('api.application.nodes.view', [
'node' => $node->id, 'node' => $node->id,
@ -112,7 +112,7 @@ class NodeController extends ApplicationApiController
); );
return $this->fractal->item($node) return $this->fractal->item($node)
->transformWith($this->getTransformer(NodeTransformer::class)) ->transformWith(NodeTransformer::class)
->toArray(); ->toArray();
} }

View file

@ -38,7 +38,7 @@ class NodeDeploymentController extends ApplicationApiController
->handle($request->query('per_page'), $request->query('page')); ->handle($request->query('per_page'), $request->query('page'));
return $this->fractal->collection($nodes) return $this->fractal->collection($nodes)
->transformWith($this->getTransformer(NodeTransformer::class)) ->transformWith(NodeTransformer::class)
->toArray(); ->toArray();
} }
} }

View file

@ -43,7 +43,7 @@ class RoleController extends ApplicationApiController
->paginate($perPage); ->paginate($perPage);
return $this->fractal->collection($roles) return $this->fractal->collection($roles)
->transformWith($this->getTransformer(AdminRoleTransformer::class)) ->transformWith(AdminRoleTransformer::class)
->toArray(); ->toArray();
} }
@ -55,7 +55,7 @@ class RoleController extends ApplicationApiController
public function view(GetRoleRequest $request, AdminRole $role): array public function view(GetRoleRequest $request, AdminRole $role): array
{ {
return $this->fractal->item($role) return $this->fractal->item($role)
->transformWith($this->getTransformer(AdminRoleTransformer::class)) ->transformWith(AdminRoleTransformer::class)
->toArray(); ->toArray();
} }
@ -72,7 +72,7 @@ class RoleController extends ApplicationApiController
$role = AdminRole::query()->create($data); $role = AdminRole::query()->create($data);
return $this->fractal->item($role) return $this->fractal->item($role)
->transformWith($this->getTransformer(AdminRoleTransformer::class)) ->transformWith(AdminRoleTransformer::class)
->respond(JsonResponse::HTTP_CREATED); ->respond(JsonResponse::HTTP_CREATED);
} }
@ -86,7 +86,7 @@ class RoleController extends ApplicationApiController
$role->update($request->validated()); $role->update($request->validated());
return $this->fractal->item($role) return $this->fractal->item($role)
->transformWith($this->getTransformer(AdminRoleTransformer::class)) ->transformWith(AdminRoleTransformer::class)
->toArray(); ->toArray();
} }

View file

@ -46,7 +46,7 @@ class DatabaseController extends ApplicationApiController
public function index(GetServerDatabasesRequest $request, Server $server): array public function index(GetServerDatabasesRequest $request, Server $server): array
{ {
return $this->fractal->collection($server->databases) return $this->fractal->collection($server->databases)
->transformWith($this->getTransformer(ServerDatabaseTransformer::class)) ->transformWith(ServerDatabaseTransformer::class)
->toArray(); ->toArray();
} }
@ -58,7 +58,7 @@ class DatabaseController extends ApplicationApiController
public function view(GetServerDatabaseRequest $request, Server $server, Database $database): array public function view(GetServerDatabaseRequest $request, Server $server, Database $database): array
{ {
return $this->fractal->item($database) return $this->fractal->item($database)
->transformWith($this->getTransformer(ServerDatabaseTransformer::class)) ->transformWith(ServerDatabaseTransformer::class)
->toArray(); ->toArray();
} }
@ -86,7 +86,7 @@ class DatabaseController extends ApplicationApiController
])); ]));
return $this->fractal->item($database) return $this->fractal->item($database)
->transformWith($this->getTransformer(ServerDatabaseTransformer::class)) ->transformWith(ServerDatabaseTransformer::class)
->addMeta([ ->addMeta([
'resource' => route('api.application.servers.databases.view', [ 'resource' => route('api.application.servers.databases.view', [
'server' => $server->id, 'server' => $server->id,

View file

@ -19,7 +19,7 @@ class ExternalServerController extends ApplicationApiController
$server = Server::query()->where('external_id', $external_id)->firstOrFail(); $server = Server::query()->where('external_id', $external_id)->firstOrFail();
return $this->fractal->item($server) return $this->fractal->item($server)
->transformWith($this->getTransformer(ServerTransformer::class)) ->transformWith(ServerTransformer::class)
->toArray(); ->toArray();
} }
} }

View file

@ -52,7 +52,7 @@ class ServerController extends ApplicationApiController
->paginate($perPage); ->paginate($perPage);
return $this->fractal->collection($servers) return $this->fractal->collection($servers)
->transformWith($this->getTransformer(ServerTransformer::class)) ->transformWith(ServerTransformer::class)
->toArray(); ->toArray();
} }
@ -71,7 +71,7 @@ class ServerController extends ApplicationApiController
$server = $this->creationService->handle($request->validated(), $request->getDeploymentObject()); $server = $this->creationService->handle($request->validated(), $request->getDeploymentObject());
return $this->fractal->item($server) return $this->fractal->item($server)
->transformWith($this->getTransformer(ServerTransformer::class)) ->transformWith(ServerTransformer::class)
->respond(Response::HTTP_CREATED); ->respond(Response::HTTP_CREATED);
} }
@ -83,7 +83,7 @@ class ServerController extends ApplicationApiController
public function view(GetServerRequest $request, Server $server): array public function view(GetServerRequest $request, Server $server): array
{ {
return $this->fractal->item($server) return $this->fractal->item($server)
->transformWith($this->getTransformer(ServerTransformer::class)) ->transformWith(ServerTransformer::class)
->toArray(); ->toArray();
} }

View file

@ -41,7 +41,7 @@ class ServerDetailsController extends ApplicationApiController
); );
return $this->fractal->item($server) return $this->fractal->item($server)
->transformWith($this->getTransformer(ServerTransformer::class)) ->transformWith(ServerTransformer::class)
->toArray(); ->toArray();
} }
@ -55,7 +55,7 @@ class ServerDetailsController extends ApplicationApiController
$server = $this->buildModificationService->handle($server, $request->validated()); $server = $this->buildModificationService->handle($server, $request->validated());
return $this->fractal->item($server) return $this->fractal->item($server)
->transformWith($this->getTransformer(ServerTransformer::class)) ->transformWith(ServerTransformer::class)
->toArray(); ->toArray();
} }
} }

View file

@ -35,7 +35,7 @@ class StartupController extends ApplicationApiController
->handle($server, $request->validated()); ->handle($server, $request->validated());
return $this->fractal->item($server) return $this->fractal->item($server)
->transformWith($this->getTransformer(ServerTransformer::class)) ->transformWith(ServerTransformer::class)
->toArray(); ->toArray();
} }
} }

View file

@ -19,7 +19,7 @@ class ExternalUserController extends ApplicationApiController
$user = User::query()->where('external_id', $external_id)->firstOrFail(); $user = User::query()->where('external_id', $external_id)->firstOrFail();
return $this->fractal->item($user) return $this->fractal->item($user)
->transformWith($this->getTransformer(UserTransformer::class)) ->transformWith(UserTransformer::class)
->toArray(); ->toArray();
} }
} }

View file

@ -63,7 +63,7 @@ class UserController extends ApplicationApiController
->paginate($perPage); ->paginate($perPage);
return $this->fractal->collection($users) return $this->fractal->collection($users)
->transformWith($this->getTransformer(UserTransformer::class)) ->transformWith(UserTransformer::class)
->toArray(); ->toArray();
} }
@ -76,7 +76,7 @@ class UserController extends ApplicationApiController
public function view(GetUserRequest $request, User $user): array public function view(GetUserRequest $request, User $user): array
{ {
return $this->fractal->item($user) return $this->fractal->item($user)
->transformWith($this->getTransformer(UserTransformer::class)) ->transformWith(UserTransformer::class)
->toArray(); ->toArray();
} }
@ -98,7 +98,7 @@ class UserController extends ApplicationApiController
$user = $this->updateService->handle($user, $request->validated()); $user = $this->updateService->handle($user, $request->validated());
return $this->fractal->item($user) return $this->fractal->item($user)
->transformWith($this->getTransformer(UserTransformer::class)) ->transformWith(UserTransformer::class)
->toArray(); ->toArray();
} }
@ -114,7 +114,7 @@ class UserController extends ApplicationApiController
$user = $this->creationService->handle($request->validated()); $user = $this->creationService->handle($request->validated());
return $this->fractal->item($user) return $this->fractal->item($user)
->transformWith($this->getTransformer(UserTransformer::class)) ->transformWith(UserTransformer::class)
->addMeta([ ->addMeta([
'resource' => route('api.application.users.view', [ 'resource' => route('api.application.users.view', [
'user' => $user->id, 'user' => $user->id,

View file

@ -19,7 +19,7 @@ class ApiKeyController extends ClientApiController
public function index(AccountApiRequest $request): array public function index(AccountApiRequest $request): array
{ {
return $this->fractal->collection($request->user()->tokens) return $this->fractal->collection($request->user()->tokens)
->transformWith($this->getTransformer(PersonalAccessTokenTransformer::class)) ->transformWith(PersonalAccessTokenTransformer::class)
->toArray(); ->toArray();
} }
@ -40,7 +40,7 @@ class ApiKeyController extends ClientApiController
[$token, $plaintext] = $request->user()->createToken($request->input('description')); [$token, $plaintext] = $request->user()->createToken($request->input('description'));
return $this->fractal->item($token) return $this->fractal->item($token)
->transformWith($this->getTransformer(PersonalAccessTokenTransformer::class)) ->transformWith(PersonalAccessTokenTransformer::class)
->addMeta([ ->addMeta([
'secret_token' => $plaintext, 'secret_token' => $plaintext,
]) ])

View file

@ -2,7 +2,6 @@
namespace Pterodactyl\Http\Controllers\Api\Client; namespace Pterodactyl\Http\Controllers\Api\Client;
use Webmozart\Assert\Assert;
use Pterodactyl\Transformers\Api\Transformer; use Pterodactyl\Transformers\Api\Transformer;
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController; use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
@ -39,20 +38,4 @@ abstract class ClientApiController extends ApplicationApiController
return trim($item); return trim($item);
}, explode(',', $includes)); }, explode(',', $includes));
} }
/**
* Return an instance of an application transformer.
*
* @return \Pterodactyl\Transformers\Api\Transformer
*
* @deprecated
*/
public function getTransformer(string $class)
{
$transformer = new $class;
Assert::same(substr($class, 0, strlen(class_basename($class)) * -1), '\Pterodactyl\Transformers\Api\Client\\');
return $transformer;
}
} }

View file

@ -34,7 +34,7 @@ class ClientController extends ClientApiController
public function index(GetServersRequest $request): array public function index(GetServersRequest $request): array
{ {
$user = $request->user(); $user = $request->user();
$transformer = $this->getTransformer(ServerTransformer::class); $transformer = ServerTransformer::class;
// Start the query builder and ensure we eager load any requested relationships from the request. // Start the query builder and ensure we eager load any requested relationships from the request.
$builder = QueryBuilder::for( $builder = QueryBuilder::for(

View file

@ -20,7 +20,7 @@ class SSHKeyController extends ClientApiController
public function index(Request $request): \Pterodactyl\Extensions\Spatie\Fractalistic\Fractal public function index(Request $request): \Pterodactyl\Extensions\Spatie\Fractalistic\Fractal
{ {
return $this->fractal->collection(UserSSHKey::query()->where('user_id', '=', $request->user()->id)->get()) return $this->fractal->collection(UserSSHKey::query()->where('user_id', '=', $request->user()->id)->get())
->transformWith($this->getTransformer(UserSSHKeyTransformer::class)); ->transformWith(UserSSHKeyTransformer::class);
} }
/** /**
@ -42,7 +42,7 @@ class SSHKeyController extends ClientApiController
$key = UserSSHKey::query()->create($data); $key = UserSSHKey::query()->create($data);
return $this->fractal->item($key) return $this->fractal->item($key)
->transformWith($this->getTransformer(UserSSHKeyTransformer::class)) ->transformWith(UserSSHKeyTransformer::class)
->respond(JsonResponse::HTTP_CREATED); ->respond(JsonResponse::HTTP_CREATED);
} }

View file

@ -63,7 +63,7 @@ class BackupController extends ClientApiController
$limit = min($request->query('per_page') ?? 20, 50); $limit = min($request->query('per_page') ?? 20, 50);
return $this->fractal->collection($server->backups()->paginate($limit)) return $this->fractal->collection($server->backups()->paginate($limit))
->transformWith($this->getTransformer(BackupTransformer::class)) ->transformWith(BackupTransformer::class)
->addMeta([ ->addMeta([
'backup_count' => $this->repository->getNonFailedBackups($server)->count(), 'backup_count' => $this->repository->getNonFailedBackups($server)->count(),
]) ])
@ -100,7 +100,7 @@ class BackupController extends ClientApiController
}); });
return $this->fractal->item($backup) return $this->fractal->item($backup)
->transformWith($this->getTransformer(BackupTransformer::class)) ->transformWith(BackupTransformer::class)
->toArray(); ->toArray();
} }
@ -126,7 +126,7 @@ class BackupController extends ClientApiController
$backup->refresh(); $backup->refresh();
return $this->fractal->item($backup) return $this->fractal->item($backup)
->transformWith($this->getTransformer(BackupTransformer::class)) ->transformWith(BackupTransformer::class)
->toArray(); ->toArray();
} }
@ -142,7 +142,7 @@ class BackupController extends ClientApiController
} }
return $this->fractal->item($backup) return $this->fractal->item($backup)
->transformWith($this->getTransformer(BackupTransformer::class)) ->transformWith(BackupTransformer::class)
->toArray(); ->toArray();
} }

View file

@ -48,7 +48,7 @@ class DatabaseController extends ClientApiController
public function index(GetDatabasesRequest $request, Server $server): array public function index(GetDatabasesRequest $request, Server $server): array
{ {
return $this->fractal->collection($server->databases) return $this->fractal->collection($server->databases)
->transformWith($this->getTransformer(DatabaseTransformer::class)) ->transformWith(DatabaseTransformer::class)
->toArray(); ->toArray();
} }
@ -65,7 +65,7 @@ class DatabaseController extends ClientApiController
return $this->fractal->item($database) return $this->fractal->item($database)
->parseIncludes(['password']) ->parseIncludes(['password'])
->transformWith($this->getTransformer(DatabaseTransformer::class)) ->transformWith(DatabaseTransformer::class)
->toArray(); ->toArray();
} }
@ -82,7 +82,7 @@ class DatabaseController extends ClientApiController
return $this->fractal->item($database) return $this->fractal->item($database)
->parseIncludes(['password']) ->parseIncludes(['password'])
->transformWith($this->getTransformer(DatabaseTransformer::class)) ->transformWith(DatabaseTransformer::class)
->toArray(); ->toArray();
} }

View file

@ -57,7 +57,7 @@ class FileController extends ClientApiController
->getDirectory($request->get('directory') ?? '/'); ->getDirectory($request->get('directory') ?? '/');
return $this->fractal->collection($contents) return $this->fractal->collection($contents)
->transformWith($this->getTransformer(FileObjectTransformer::class)) ->transformWith(FileObjectTransformer::class)
->toArray(); ->toArray();
} }
@ -202,7 +202,7 @@ class FileController extends ClientApiController
}); });
return $this->fractal->item($file) return $this->fractal->item($file)
->transformWith($this->getTransformer(FileObjectTransformer::class)) ->transformWith(FileObjectTransformer::class)
->toArray(); ->toArray();
} }

View file

@ -47,7 +47,7 @@ class NetworkAllocationController extends ClientApiController
public function index(GetNetworkRequest $request, Server $server): array public function index(GetNetworkRequest $request, Server $server): array
{ {
return $this->fractal->collection($server->allocations) return $this->fractal->collection($server->allocations)
->transformWith($this->getTransformer(AllocationTransformer::class)) ->transformWith(AllocationTransformer::class)
->toArray(); ->toArray();
} }
@ -65,7 +65,7 @@ class NetworkAllocationController extends ClientApiController
]); ]);
return $this->fractal->item($allocation) return $this->fractal->item($allocation)
->transformWith($this->getTransformer(AllocationTransformer::class)) ->transformWith(AllocationTransformer::class)
->toArray(); ->toArray();
} }
@ -81,7 +81,7 @@ class NetworkAllocationController extends ClientApiController
$this->serverRepository->update($server->id, ['allocation_id' => $allocation->id]); $this->serverRepository->update($server->id, ['allocation_id' => $allocation->id]);
return $this->fractal->item($allocation) return $this->fractal->item($allocation)
->transformWith($this->getTransformer(AllocationTransformer::class)) ->transformWith(AllocationTransformer::class)
->toArray(); ->toArray();
} }
@ -100,7 +100,7 @@ class NetworkAllocationController extends ClientApiController
$allocation = $this->assignableAllocationService->handle($server); $allocation = $this->assignableAllocationService->handle($server);
return $this->fractal->item($allocation) return $this->fractal->item($allocation)
->transformWith($this->getTransformer(AllocationTransformer::class)) ->transformWith(AllocationTransformer::class)
->toArray(); ->toArray();
} }

View file

@ -42,7 +42,7 @@ class ResourceUtilizationController extends ClientApiController
}); });
return $this->fractal->item($stats) return $this->fractal->item($stats)
->transformWith($this->getTransformer(StatsTransformer::class)) ->transformWith(StatsTransformer::class)
->toArray(); ->toArray();
} }
} }

View file

@ -49,7 +49,7 @@ class ScheduleController extends ClientApiController
$schedules->loadMissing('tasks'); $schedules->loadMissing('tasks');
return $this->fractal->collection($schedules) return $this->fractal->collection($schedules)
->transformWith($this->getTransformer(ScheduleTransformer::class)) ->transformWith(ScheduleTransformer::class)
->toArray(); ->toArray();
} }
@ -77,7 +77,7 @@ class ScheduleController extends ClientApiController
]); ]);
return $this->fractal->item($model) return $this->fractal->item($model)
->transformWith($this->getTransformer(ScheduleTransformer::class)) ->transformWith(ScheduleTransformer::class)
->toArray(); ->toArray();
} }
@ -91,7 +91,7 @@ class ScheduleController extends ClientApiController
$schedule->loadMissing('tasks'); $schedule->loadMissing('tasks');
return $this->fractal->item($schedule) return $this->fractal->item($schedule)
->transformWith($this->getTransformer(ScheduleTransformer::class)) ->transformWith(ScheduleTransformer::class)
->toArray(); ->toArray();
} }
@ -130,7 +130,7 @@ class ScheduleController extends ClientApiController
$this->repository->update($schedule->id, $data); $this->repository->update($schedule->id, $data);
return $this->fractal->item($schedule->refresh()) return $this->fractal->item($schedule->refresh())
->transformWith($this->getTransformer(ScheduleTransformer::class)) ->transformWith(ScheduleTransformer::class)
->toArray(); ->toArray();
} }

View file

@ -64,7 +64,7 @@ class ScheduleTaskController extends ClientApiController
]); ]);
return $this->fractal->item($task) return $this->fractal->item($task)
->transformWith($this->getTransformer(TaskTransformer::class)) ->transformWith(TaskTransformer::class)
->toArray(); ->toArray();
} }
@ -94,7 +94,7 @@ class ScheduleTaskController extends ClientApiController
]); ]);
return $this->fractal->item($task->refresh()) return $this->fractal->item($task->refresh())
->transformWith($this->getTransformer(TaskTransformer::class)) ->transformWith(TaskTransformer::class)
->toArray(); ->toArray();
} }

View file

@ -34,7 +34,7 @@ class ServerController extends ClientApiController
public function index(GetServerRequest $request, Server $server): array public function index(GetServerRequest $request, Server $server): array
{ {
return $this->fractal->item($server) return $this->fractal->item($server)
->transformWith($this->getTransformer(ServerTransformer::class)) ->transformWith(ServerTransformer::class)
->addMeta([ ->addMeta([
'is_server_owner' => $request->user()->id === $server->owner_id, 'is_server_owner' => $request->user()->id === $server->owner_id,
'user_permissions' => $this->permissionsService->handle($server, $request->user()), 'user_permissions' => $this->permissionsService->handle($server, $request->user()),

View file

@ -42,7 +42,7 @@ class StartupController extends ClientApiController
return $this->fractal->collection( return $this->fractal->collection(
$server->variables()->where('user_viewable', true)->get() $server->variables()->where('user_viewable', true)->get()
) )
->transformWith($this->getTransformer(EggVariableTransformer::class)) ->transformWith(EggVariableTransformer::class)
->addMeta([ ->addMeta([
'startup_command' => $startup, 'startup_command' => $startup,
'docker_images' => $server->egg->docker_images, 'docker_images' => $server->egg->docker_images,
@ -86,7 +86,7 @@ class StartupController extends ClientApiController
$startup = $this->startupCommandService->handle($server, false); $startup = $this->startupCommandService->handle($server, false);
return $this->fractal->item($variable) return $this->fractal->item($variable)
->transformWith($this->getTransformer(EggVariableTransformer::class)) ->transformWith(EggVariableTransformer::class)
->addMeta([ ->addMeta([
'startup_command' => $startup, 'startup_command' => $startup,
'raw_startup_command' => $server->startup, 'raw_startup_command' => $server->startup,

View file

@ -48,7 +48,7 @@ class SubuserController extends ClientApiController
public function index(GetSubuserRequest $request, Server $server): array public function index(GetSubuserRequest $request, Server $server): array
{ {
return $this->fractal->collection($server->subusers) return $this->fractal->collection($server->subusers)
->transformWith($this->getTransformer(SubuserTransformer::class)) ->transformWith(SubuserTransformer::class)
->toArray(); ->toArray();
} }
@ -60,7 +60,7 @@ class SubuserController extends ClientApiController
public function view(GetSubuserRequest $request, Server $server, Subuser $subuser): array public function view(GetSubuserRequest $request, Server $server, Subuser $subuser): array
{ {
return $this->fractal->item($subuser) return $this->fractal->item($subuser)
->transformWith($this->getTransformer(SubuserTransformer::class)) ->transformWith(SubuserTransformer::class)
->toArray(); ->toArray();
} }
@ -81,7 +81,7 @@ class SubuserController extends ClientApiController
); );
return $this->fractal->item($response) return $this->fractal->item($response)
->transformWith($this->getTransformer(SubuserTransformer::class)) ->transformWith(SubuserTransformer::class)
->toArray(); ->toArray();
} }
@ -117,7 +117,7 @@ class SubuserController extends ClientApiController
} }
return $this->fractal->item($subuser->refresh()) return $this->fractal->item($subuser->refresh())
->transformWith($this->getTransformer(SubuserTransformer::class)) ->transformWith(SubuserTransformer::class)
->toArray(); ->toArray();
} }

View file

@ -24,7 +24,7 @@ class WebauthnController extends ClientApiController
public function index(Request $request): array public function index(Request $request): array
{ {
return $this->fractal->collection(WebauthnKey::query()->where('user_id', '=', $request->user()->id)->get()) return $this->fractal->collection(WebauthnKey::query()->where('user_id', '=', $request->user()->id)->get())
->transformWith($this->getTransformer(WebauthnKeyTransformer::class)) ->transformWith(WebauthnKeyTransformer::class)
->toArray(); ->toArray();
} }
@ -88,7 +88,7 @@ class WebauthnController extends ClientApiController
); );
return $this->fractal->item($webauthnKey) return $this->fractal->item($webauthnKey)
->transformWith($this->getTransformer(WebauthnKeyTransformer::class)) ->transformWith(WebauthnKeyTransformer::class)
->toArray(); ->toArray();
} catch (Exception $e) { } catch (Exception $e) {
return new JsonResponse([ return new JsonResponse([

View file

@ -5,7 +5,6 @@ namespace Pterodactyl\Tests\Integration\Api\Application;
use Pterodactyl\Models\User; use Pterodactyl\Models\User;
use Pterodactyl\Models\ApiKey; use Pterodactyl\Models\ApiKey;
use Pterodactyl\Services\Acl\Api\AdminAcl; use Pterodactyl\Services\Acl\Api\AdminAcl;
use Pterodactyl\Transformers\Api\Transformer;
use Pterodactyl\Tests\Integration\IntegrationTestCase; use Pterodactyl\Tests\Integration\IntegrationTestCase;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Pterodactyl\Tests\Traits\Integration\CreatesTestModels; use Pterodactyl\Tests\Traits\Integration\CreatesTestModels;
@ -122,16 +121,4 @@ abstract class ApplicationApiIntegrationTestCase extends IntegrationTestCase
'r_server_databases' => AdminAcl::READ | AdminAcl::WRITE, 'r_server_databases' => AdminAcl::READ | AdminAcl::WRITE,
], $permissions)); ], $permissions));
} }
/**
* Return a transformer that can be used for testing purposes.
*
* @param string $abstract
*
* @return \Pterodactyl\Transformers\Api\Transformer
*/
protected function getTransformer(string $abstract): Transformer
{
return new $abstract;
}
} }

View file

@ -56,7 +56,7 @@ class EggControllerTest extends ApplicationApiIntegrationTestCase
$egg = $eggs->where('id', '=', $datum['attributes']['id'])->first(); $egg = $eggs->where('id', '=', $datum['attributes']['id'])->first();
$expected = json_encode(Arr::sortRecursive($datum['attributes'])); $expected = json_encode(Arr::sortRecursive($datum['attributes']));
$actual = json_encode(Arr::sortRecursive($this->getTransformer(EggTransformer::class)->transform($egg))); $actual = json_encode(Arr::sortRecursive((new EggTransformer())->transform($egg)));
$this->assertSame( $this->assertSame(
$expected, $expected,
@ -84,7 +84,7 @@ class EggControllerTest extends ApplicationApiIntegrationTestCase
$response->assertJson([ $response->assertJson([
'object' => 'egg', 'object' => 'egg',
'attributes' => $this->getTransformer(EggTransformer::class)->transform($egg), 'attributes' => (new EggTransformer())->transform($egg),
], true); ], true);
} }

View file

@ -118,7 +118,7 @@ class LocationControllerTest extends ApplicationApiIntegrationTestCase
'data' => [ 'data' => [
[ [
'object' => 'node', 'object' => 'node',
'attributes' => $this->getTransformer(NodeTransformer::class)->transform($server->getRelation('node')), 'attributes' => (new NodeTransformer())->transform($server->getRelation('node')),
], ],
], ],
], ],
@ -127,7 +127,7 @@ class LocationControllerTest extends ApplicationApiIntegrationTestCase
'data' => [ 'data' => [
[ [
'object' => 'server', 'object' => 'server',
'attributes' => $this->getTransformer(ServerTransformer::class)->transform($server), 'attributes' => (new ServerTransformer())->transform($server),
], ],
], ],
], ],

View file

@ -59,7 +59,7 @@ class NestControllerTest extends ApplicationApiIntegrationTestCase
foreach ($nests as $nest) { foreach ($nests as $nest) {
$response->assertJsonFragment([ $response->assertJsonFragment([
'object' => 'nest', 'object' => 'nest',
'attributes' => $this->getTransformer(NestTransformer::class)->transform($nest), 'attributes' => (new NestTransformer())->transform($nest),
]); ]);
} }
} }
@ -80,7 +80,7 @@ class NestControllerTest extends ApplicationApiIntegrationTestCase
$response->assertJson([ $response->assertJson([
'object' => 'nest', 'object' => 'nest',
'attributes' => $this->getTransformer(NestTransformer::class)->transform($nest), 'attributes' => (new NestTransformer())->transform($nest),
]); ]);
} }

View file

@ -140,7 +140,7 @@ class UserControllerTest extends ApplicationApiIntegrationTestCase
'data' => [ 'data' => [
[ [
'object' => 'server', 'object' => 'server',
'attributes' => $this->getTransformer(ServerTransformer::class)->transform($server), 'attributes' => (new ServerTransformer())->transform($server),
], ],
], ],
]); ]);
@ -238,7 +238,7 @@ class UserControllerTest extends ApplicationApiIntegrationTestCase
$user = User::where('username', 'testuser')->first(); $user = User::where('username', 'testuser')->first();
$response->assertJson([ $response->assertJson([
'object' => 'user', 'object' => 'user',
'attributes' => $this->getTransformer(UserTransformer::class)->transform($user), 'attributes' => (new UserTransformer())->transform($user),
'meta' => [ 'meta' => [
'resource' => route('api.application.users.view', $user->id), 'resource' => route('api.application.users.view', $user->id),
], ],
@ -268,7 +268,7 @@ class UserControllerTest extends ApplicationApiIntegrationTestCase
$response->assertJson([ $response->assertJson([
'object' => 'user', 'object' => 'user',
'attributes' => $this->getTransformer(UserTransformer::class)->transform($user), 'attributes' => (new UserTransformer())->transform($user),
]); ]);
} }