Upgrade to Laravel 9 (#4413)
Co-authored-by: DaneEveritt <dane@daneeveritt.com>
This commit is contained in:
parent
95e15d2c8a
commit
cbcf62086f
573 changed files with 4387 additions and 9411 deletions
|
@ -4,7 +4,9 @@ namespace Pterodactyl\Transformers\Api\Application;
|
|||
|
||||
use Pterodactyl\Models\Node;
|
||||
use Pterodactyl\Models\Server;
|
||||
use League\Fractal\Resource\Item;
|
||||
use Pterodactyl\Models\Allocation;
|
||||
use League\Fractal\Resource\NullResource;
|
||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||
|
||||
class AllocationTransformer extends BaseTransformer
|
||||
|
@ -24,10 +26,8 @@ class AllocationTransformer extends BaseTransformer
|
|||
|
||||
/**
|
||||
* Return a generic transformed allocation array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function transform(Allocation $allocation)
|
||||
public function transform(Allocation $allocation): array
|
||||
{
|
||||
return [
|
||||
'id' => $allocation->id,
|
||||
|
@ -42,11 +42,9 @@ class AllocationTransformer extends BaseTransformer
|
|||
/**
|
||||
* Load the node relationship onto a given transformation.
|
||||
*
|
||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeNode(Allocation $allocation)
|
||||
public function includeNode(Allocation $allocation): Item|NullResource
|
||||
{
|
||||
if (!$this->authorize(AdminAcl::RESOURCE_NODES)) {
|
||||
return $this->null();
|
||||
|
@ -62,11 +60,9 @@ class AllocationTransformer extends BaseTransformer
|
|||
/**
|
||||
* Load the server relationship onto a given transformation.
|
||||
*
|
||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeServer(Allocation $allocation)
|
||||
public function includeServer(Allocation $allocation): Item|NullResource
|
||||
{
|
||||
if (!$this->authorize(AdminAcl::RESOURCE_SERVERS) || !$allocation->server) {
|
||||
return $this->null();
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Pterodactyl\Transformers\Api\Application;
|
||||
|
||||
use Carbon\CarbonImmutable;
|
||||
use Carbon\CarbonInterface;
|
||||
use Illuminate\Http\Request;
|
||||
use Webmozart\Assert\Assert;
|
||||
use Pterodactyl\Models\ApiKey;
|
||||
|
@ -38,8 +39,6 @@ abstract class BaseTransformer extends TransformerAbstract
|
|||
|
||||
/**
|
||||
* Sets the request on the instance.
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function setRequest(Request $request): self
|
||||
{
|
||||
|
@ -50,10 +49,8 @@ abstract class BaseTransformer extends TransformerAbstract
|
|||
|
||||
/**
|
||||
* Returns a new transformer instance with the request set on the instance.
|
||||
*
|
||||
* @return \Pterodactyl\Transformers\Api\Application\BaseTransformer
|
||||
*/
|
||||
public static function fromRequest(Request $request)
|
||||
public static function fromRequest(Request $request): BaseTransformer
|
||||
{
|
||||
return app(static::class)->setRequest($request);
|
||||
}
|
||||
|
@ -81,7 +78,7 @@ abstract class BaseTransformer extends TransformerAbstract
|
|||
return $this->request->user()->root_admin;
|
||||
}
|
||||
|
||||
return AdminAcl::check($token, $resource, AdminAcl::READ);
|
||||
return AdminAcl::check($token, $resource);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -96,7 +93,6 @@ abstract class BaseTransformer extends TransformerAbstract
|
|||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*
|
||||
* @noinspection PhpUndefinedClassInspection
|
||||
* @noinspection PhpDocSignatureInspection
|
||||
*/
|
||||
protected function makeTransformer(string $abstract)
|
||||
|
@ -111,8 +107,8 @@ abstract class BaseTransformer extends TransformerAbstract
|
|||
*/
|
||||
protected function formatTimestamp(string $timestamp): string
|
||||
{
|
||||
return CarbonImmutable::createFromFormat(CarbonImmutable::DEFAULT_TO_STRING_FORMAT, $timestamp)
|
||||
return CarbonImmutable::createFromFormat(CarbonInterface::DEFAULT_TO_STRING_FORMAT, $timestamp)
|
||||
->setTimezone(self::RESPONSE_TIMEZONE)
|
||||
->toIso8601String();
|
||||
->toAtomString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ namespace Pterodactyl\Transformers\Api\Application;
|
|||
|
||||
use Pterodactyl\Models\Database;
|
||||
use Pterodactyl\Models\DatabaseHost;
|
||||
use League\Fractal\Resource\Collection;
|
||||
use League\Fractal\Resource\NullResource;
|
||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||
|
||||
class DatabaseHostTransformer extends BaseTransformer
|
||||
|
@ -22,10 +24,8 @@ class DatabaseHostTransformer extends BaseTransformer
|
|||
|
||||
/**
|
||||
* Transform database host into a representation for the application API.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function transform(DatabaseHost $model)
|
||||
public function transform(DatabaseHost $model): array
|
||||
{
|
||||
return [
|
||||
'id' => $model->id,
|
||||
|
@ -34,19 +34,17 @@ class DatabaseHostTransformer extends BaseTransformer
|
|||
'port' => $model->port,
|
||||
'username' => $model->username,
|
||||
'node' => $model->node_id,
|
||||
'created_at' => $model->created_at->toIso8601String(),
|
||||
'updated_at' => $model->updated_at->toIso8601String(),
|
||||
'created_at' => $model->created_at->toAtomString(),
|
||||
'updated_at' => $model->updated_at->toAtomString(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Include the databases associated with this host.
|
||||
*
|
||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeDatabases(DatabaseHost $model)
|
||||
public function includeDatabases(DatabaseHost $model): Collection|NullResource
|
||||
{
|
||||
if (!$this->authorize(AdminAcl::RESOURCE_SERVER_DATABASES)) {
|
||||
return $this->null();
|
||||
|
|
|
@ -6,7 +6,10 @@ use Illuminate\Support\Arr;
|
|||
use Pterodactyl\Models\Egg;
|
||||
use Pterodactyl\Models\Nest;
|
||||
use Pterodactyl\Models\Server;
|
||||
use League\Fractal\Resource\Item;
|
||||
use Pterodactyl\Models\EggVariable;
|
||||
use League\Fractal\Resource\Collection;
|
||||
use League\Fractal\Resource\NullResource;
|
||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||
|
||||
class EggTransformer extends BaseTransformer
|
||||
|
@ -34,9 +37,9 @@ class EggTransformer extends BaseTransformer
|
|||
* Transform an Egg model into a representation that can be consumed by
|
||||
* the application api.
|
||||
*
|
||||
* @return array
|
||||
* @throws \JsonException
|
||||
*/
|
||||
public function transform(Egg $model)
|
||||
public function transform(Egg $model): array
|
||||
{
|
||||
$files = json_decode($model->config_files, true, 512, JSON_THROW_ON_ERROR);
|
||||
if (empty($files)) {
|
||||
|
@ -79,11 +82,9 @@ class EggTransformer extends BaseTransformer
|
|||
/**
|
||||
* Include the Nest relationship for the given Egg in the transformation.
|
||||
*
|
||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeNest(Egg $model)
|
||||
public function includeNest(Egg $model): Item|NullResource
|
||||
{
|
||||
if (!$this->authorize(AdminAcl::RESOURCE_NESTS)) {
|
||||
return $this->null();
|
||||
|
@ -97,11 +98,9 @@ class EggTransformer extends BaseTransformer
|
|||
/**
|
||||
* Include the Servers relationship for the given Egg in the transformation.
|
||||
*
|
||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeServers(Egg $model)
|
||||
public function includeServers(Egg $model): Collection|NullResource
|
||||
{
|
||||
if (!$this->authorize(AdminAcl::RESOURCE_SERVERS)) {
|
||||
return $this->null();
|
||||
|
@ -115,10 +114,8 @@ class EggTransformer extends BaseTransformer
|
|||
/**
|
||||
* Include more detailed information about the configuration if this Egg is
|
||||
* extending another.
|
||||
*
|
||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||
*/
|
||||
public function includeConfig(Egg $model)
|
||||
public function includeConfig(Egg $model): Item|NullResource
|
||||
{
|
||||
if (is_null($model->config_from)) {
|
||||
return $this->null();
|
||||
|
@ -139,10 +136,8 @@ class EggTransformer extends BaseTransformer
|
|||
/**
|
||||
* Include more detailed information about the script configuration if the
|
||||
* Egg is extending another.
|
||||
*
|
||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||
*/
|
||||
public function includeScript(Egg $model)
|
||||
public function includeScript(Egg $model): Item|NullResource
|
||||
{
|
||||
if (is_null($model->copy_script_from)) {
|
||||
return $this->null();
|
||||
|
@ -163,11 +158,9 @@ class EggTransformer extends BaseTransformer
|
|||
/**
|
||||
* Include the variables that are defined for this Egg.
|
||||
*
|
||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeVariables(Egg $model)
|
||||
public function includeVariables(Egg $model): Collection|NullResource
|
||||
{
|
||||
if (!$this->authorize(AdminAcl::RESOURCE_EGGS)) {
|
||||
return $this->null();
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
namespace Pterodactyl\Transformers\Api\Application;
|
||||
|
||||
use Pterodactyl\Models\Location;
|
||||
use League\Fractal\Resource\Collection;
|
||||
use League\Fractal\Resource\NullResource;
|
||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||
|
||||
class LocationTransformer extends BaseTransformer
|
||||
|
@ -37,11 +39,9 @@ class LocationTransformer extends BaseTransformer
|
|||
/**
|
||||
* Return the nodes associated with this location.
|
||||
*
|
||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeServers(Location $location)
|
||||
public function includeServers(Location $location): Collection|NullResource
|
||||
{
|
||||
if (!$this->authorize(AdminAcl::RESOURCE_SERVERS)) {
|
||||
return $this->null();
|
||||
|
@ -55,11 +55,9 @@ class LocationTransformer extends BaseTransformer
|
|||
/**
|
||||
* Return the nodes associated with this location.
|
||||
*
|
||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeNodes(Location $location)
|
||||
public function includeNodes(Location $location): Collection|NullResource
|
||||
{
|
||||
if (!$this->authorize(AdminAcl::RESOURCE_NODES)) {
|
||||
return $this->null();
|
||||
|
|
|
@ -5,6 +5,8 @@ namespace Pterodactyl\Transformers\Api\Application;
|
|||
use Pterodactyl\Models\Egg;
|
||||
use Pterodactyl\Models\Nest;
|
||||
use Pterodactyl\Models\Server;
|
||||
use League\Fractal\Resource\Collection;
|
||||
use League\Fractal\Resource\NullResource;
|
||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||
|
||||
class NestTransformer extends BaseTransformer
|
||||
|
@ -27,10 +29,8 @@ class NestTransformer extends BaseTransformer
|
|||
/**
|
||||
* Transform a Nest model into a representation that can be consumed by the
|
||||
* application API.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function transform(Nest $model)
|
||||
public function transform(Nest $model): array
|
||||
{
|
||||
$response = $model->toArray();
|
||||
|
||||
|
@ -43,11 +43,9 @@ class NestTransformer extends BaseTransformer
|
|||
/**
|
||||
* Include the Eggs relationship on the given Nest model transformation.
|
||||
*
|
||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeEggs(Nest $model)
|
||||
public function includeEggs(Nest $model): Collection|NullResource
|
||||
{
|
||||
if (!$this->authorize(AdminAcl::RESOURCE_EGGS)) {
|
||||
return $this->null();
|
||||
|
@ -61,11 +59,9 @@ class NestTransformer extends BaseTransformer
|
|||
/**
|
||||
* Include the servers relationship on the given Nest model.
|
||||
*
|
||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeServers(Nest $model)
|
||||
public function includeServers(Nest $model): Collection|NullResource
|
||||
{
|
||||
if (!$this->authorize(AdminAcl::RESOURCE_SERVERS)) {
|
||||
return $this->null();
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
namespace Pterodactyl\Transformers\Api\Application;
|
||||
|
||||
use Pterodactyl\Models\Node;
|
||||
use League\Fractal\Resource\Item;
|
||||
use League\Fractal\Resource\Collection;
|
||||
use League\Fractal\Resource\NullResource;
|
||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||
|
||||
class NodeTransformer extends BaseTransformer
|
||||
|
@ -50,11 +53,9 @@ class NodeTransformer extends BaseTransformer
|
|||
/**
|
||||
* Return the nodes associated with this location.
|
||||
*
|
||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeAllocations(Node $node)
|
||||
public function includeAllocations(Node $node): Collection|NullResource
|
||||
{
|
||||
if (!$this->authorize(AdminAcl::RESOURCE_ALLOCATIONS)) {
|
||||
return $this->null();
|
||||
|
@ -72,11 +73,9 @@ class NodeTransformer extends BaseTransformer
|
|||
/**
|
||||
* Return the nodes associated with this location.
|
||||
*
|
||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeLocation(Node $node)
|
||||
public function includeLocation(Node $node): Item|NullResource
|
||||
{
|
||||
if (!$this->authorize(AdminAcl::RESOURCE_LOCATIONS)) {
|
||||
return $this->null();
|
||||
|
@ -94,11 +93,9 @@ class NodeTransformer extends BaseTransformer
|
|||
/**
|
||||
* Return the nodes associated with this location.
|
||||
*
|
||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeServers(Node $node)
|
||||
public function includeServers(Node $node): Collection|NullResource
|
||||
{
|
||||
if (!$this->authorize(AdminAcl::RESOURCE_SERVERS)) {
|
||||
return $this->null();
|
||||
|
|
|
@ -3,7 +3,9 @@
|
|||
namespace Pterodactyl\Transformers\Api\Application;
|
||||
|
||||
use Pterodactyl\Models\Database;
|
||||
use League\Fractal\Resource\Item;
|
||||
use Pterodactyl\Models\DatabaseHost;
|
||||
use League\Fractal\Resource\NullResource;
|
||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||
use Illuminate\Contracts\Encryption\Encrypter;
|
||||
|
||||
|
@ -11,10 +13,7 @@ class ServerDatabaseTransformer extends BaseTransformer
|
|||
{
|
||||
protected array $availableIncludes = ['password', 'host'];
|
||||
|
||||
/**
|
||||
* @var Encrypter
|
||||
*/
|
||||
private $encrypter;
|
||||
private Encrypter $encrypter;
|
||||
|
||||
/**
|
||||
* Perform dependency injection.
|
||||
|
@ -45,17 +44,15 @@ class ServerDatabaseTransformer extends BaseTransformer
|
|||
'username' => $model->username,
|
||||
'remote' => $model->remote,
|
||||
'max_connections' => $model->max_connections,
|
||||
'created_at' => $model->created_at->toIso8601String(),
|
||||
'updated_at' => $model->updated_at->toIso8601String(),
|
||||
'created_at' => $model->created_at->toAtomString(),
|
||||
'updated_at' => $model->updated_at->toAtomString(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Include the database password in the request.
|
||||
*
|
||||
* @return \League\Fractal\Resource\Item
|
||||
*/
|
||||
public function includePassword(Database $model)
|
||||
public function includePassword(Database $model): Item
|
||||
{
|
||||
return $this->item($model, function (Database $model) {
|
||||
return [
|
||||
|
@ -67,11 +64,9 @@ class ServerDatabaseTransformer extends BaseTransformer
|
|||
/**
|
||||
* Return the database host relationship for this server database.
|
||||
*
|
||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeHost(Database $model)
|
||||
public function includeHost(Database $model): Item|NullResource
|
||||
{
|
||||
if (!$this->authorize(AdminAcl::RESOURCE_DATABASE_HOSTS)) {
|
||||
return $this->null();
|
||||
|
|
|
@ -3,15 +3,15 @@
|
|||
namespace Pterodactyl\Transformers\Api\Application;
|
||||
|
||||
use Pterodactyl\Models\Server;
|
||||
use League\Fractal\Resource\Item;
|
||||
use League\Fractal\Resource\Collection;
|
||||
use League\Fractal\Resource\NullResource;
|
||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||
use Pterodactyl\Services\Servers\EnvironmentService;
|
||||
|
||||
class ServerTransformer extends BaseTransformer
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Servers\EnvironmentService
|
||||
*/
|
||||
private $environmentService;
|
||||
private EnvironmentService $environmentService;
|
||||
|
||||
/**
|
||||
* List of resources that can be included.
|
||||
|
@ -94,11 +94,9 @@ class ServerTransformer extends BaseTransformer
|
|||
/**
|
||||
* Return a generic array of allocations for this server.
|
||||
*
|
||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeAllocations(Server $server)
|
||||
public function includeAllocations(Server $server): Collection|NullResource
|
||||
{
|
||||
if (!$this->authorize(AdminAcl::RESOURCE_ALLOCATIONS)) {
|
||||
return $this->null();
|
||||
|
@ -112,11 +110,9 @@ class ServerTransformer extends BaseTransformer
|
|||
/**
|
||||
* Return a generic array of data about subusers for this server.
|
||||
*
|
||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeSubusers(Server $server)
|
||||
public function includeSubusers(Server $server): Collection|NullResource
|
||||
{
|
||||
if (!$this->authorize(AdminAcl::RESOURCE_USERS)) {
|
||||
return $this->null();
|
||||
|
@ -130,11 +126,9 @@ class ServerTransformer extends BaseTransformer
|
|||
/**
|
||||
* Return a generic array of data about subusers for this server.
|
||||
*
|
||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeUser(Server $server)
|
||||
public function includeUser(Server $server): Item|NullResource
|
||||
{
|
||||
if (!$this->authorize(AdminAcl::RESOURCE_USERS)) {
|
||||
return $this->null();
|
||||
|
@ -148,11 +142,9 @@ class ServerTransformer extends BaseTransformer
|
|||
/**
|
||||
* Return a generic array with nest information for this server.
|
||||
*
|
||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeNest(Server $server)
|
||||
public function includeNest(Server $server): Item|NullResource
|
||||
{
|
||||
if (!$this->authorize(AdminAcl::RESOURCE_NESTS)) {
|
||||
return $this->null();
|
||||
|
@ -166,11 +158,9 @@ class ServerTransformer extends BaseTransformer
|
|||
/**
|
||||
* Return a generic array with egg information for this server.
|
||||
*
|
||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeEgg(Server $server)
|
||||
public function includeEgg(Server $server): Item|NullResource
|
||||
{
|
||||
if (!$this->authorize(AdminAcl::RESOURCE_EGGS)) {
|
||||
return $this->null();
|
||||
|
@ -184,11 +174,9 @@ class ServerTransformer extends BaseTransformer
|
|||
/**
|
||||
* Return a generic array of data about subusers for this server.
|
||||
*
|
||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeVariables(Server $server)
|
||||
public function includeVariables(Server $server): Collection|NullResource
|
||||
{
|
||||
if (!$this->authorize(AdminAcl::RESOURCE_SERVERS)) {
|
||||
return $this->null();
|
||||
|
@ -202,11 +190,9 @@ class ServerTransformer extends BaseTransformer
|
|||
/**
|
||||
* Return a generic array with location information for this server.
|
||||
*
|
||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeLocation(Server $server)
|
||||
public function includeLocation(Server $server): Item|NullResource
|
||||
{
|
||||
if (!$this->authorize(AdminAcl::RESOURCE_LOCATIONS)) {
|
||||
return $this->null();
|
||||
|
@ -220,11 +206,9 @@ class ServerTransformer extends BaseTransformer
|
|||
/**
|
||||
* Return a generic array with node information for this server.
|
||||
*
|
||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeNode(Server $server)
|
||||
public function includeNode(Server $server): Item|NullResource
|
||||
{
|
||||
if (!$this->authorize(AdminAcl::RESOURCE_NODES)) {
|
||||
return $this->null();
|
||||
|
@ -238,11 +222,9 @@ class ServerTransformer extends BaseTransformer
|
|||
/**
|
||||
* Return a generic array with database information for this server.
|
||||
*
|
||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeDatabases(Server $server)
|
||||
public function includeDatabases(Server $server): Collection|NullResource
|
||||
{
|
||||
if (!$this->authorize(AdminAcl::RESOURCE_SERVER_DATABASES)) {
|
||||
return $this->null();
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
namespace Pterodactyl\Transformers\Api\Application;
|
||||
|
||||
use League\Fractal\Resource\Item;
|
||||
use Pterodactyl\Models\EggVariable;
|
||||
use League\Fractal\Resource\NullResource;
|
||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||
|
||||
class ServerVariableTransformer extends BaseTransformer
|
||||
|
@ -22,10 +24,8 @@ class ServerVariableTransformer extends BaseTransformer
|
|||
|
||||
/**
|
||||
* Return a generic transformed server variable array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function transform(EggVariable $variable)
|
||||
public function transform(EggVariable $variable): array
|
||||
{
|
||||
return $variable->toArray();
|
||||
}
|
||||
|
@ -33,11 +33,9 @@ class ServerVariableTransformer extends BaseTransformer
|
|||
/**
|
||||
* Return the parent service variable data.
|
||||
*
|
||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeParent(EggVariable $variable)
|
||||
public function includeParent(EggVariable $variable): Item|NullResource
|
||||
{
|
||||
if (!$this->authorize(AdminAcl::RESOURCE_EGGS)) {
|
||||
return $this->null();
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
namespace Pterodactyl\Transformers\Api\Application;
|
||||
|
||||
use Pterodactyl\Models\Subuser;
|
||||
use League\Fractal\Resource\Item;
|
||||
use League\Fractal\Resource\NullResource;
|
||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||
|
||||
class SubuserTransformer extends BaseTransformer
|
||||
|
@ -38,11 +40,9 @@ class SubuserTransformer extends BaseTransformer
|
|||
/**
|
||||
* Return a generic item of user for this subuser.
|
||||
*
|
||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeUser(Subuser $subuser)
|
||||
public function includeUser(Subuser $subuser): Item|NullResource
|
||||
{
|
||||
if (!$this->authorize(AdminAcl::RESOURCE_USERS)) {
|
||||
return $this->null();
|
||||
|
@ -56,11 +56,9 @@ class SubuserTransformer extends BaseTransformer
|
|||
/**
|
||||
* Return a generic item of server for this subuser.
|
||||
*
|
||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeServer(Subuser $subuser)
|
||||
public function includeServer(Subuser $subuser): Item|NullResource
|
||||
{
|
||||
if (!$this->authorize(AdminAcl::RESOURCE_SERVERS)) {
|
||||
return $this->null();
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
namespace Pterodactyl\Transformers\Api\Application;
|
||||
|
||||
use Pterodactyl\Models\User;
|
||||
use League\Fractal\Resource\Collection;
|
||||
use League\Fractal\Resource\NullResource;
|
||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||
|
||||
class UserTransformer extends BaseTransformer
|
||||
|
@ -44,11 +46,9 @@ class UserTransformer extends BaseTransformer
|
|||
/**
|
||||
* Return the servers associated with this user.
|
||||
*
|
||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeServers(User $user)
|
||||
public function includeServers(User $user): Collection|NullResource
|
||||
{
|
||||
if (!$this->authorize(AdminAcl::RESOURCE_SERVERS)) {
|
||||
return $this->null();
|
||||
|
|
|
@ -15,11 +15,9 @@ class AccountTransformer extends BaseClientTransformer
|
|||
}
|
||||
|
||||
/**
|
||||
* Return basic information about the currently logged in user.
|
||||
*
|
||||
* @return array
|
||||
* Return basic information about the currently logged-in user.
|
||||
*/
|
||||
public function transform(User $model)
|
||||
public function transform(User $model): array
|
||||
{
|
||||
return [
|
||||
'id' => $model->id,
|
||||
|
|
|
@ -30,7 +30,7 @@ class ActivityLogTransformer extends BaseClientTransformer
|
|||
'description' => $model->description,
|
||||
'properties' => $this->properties($model),
|
||||
'has_additional_metadata' => $this->hasAdditionalMetadata($model),
|
||||
'timestamp' => $model->timestamp->toIso8601String(),
|
||||
'timestamp' => $model->timestamp->toAtomString(),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -14,12 +14,7 @@ class AllocationTransformer extends BaseClientTransformer
|
|||
return 'allocation';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return basic information about the currently logged in user.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function transform(Allocation $model)
|
||||
public function transform(Allocation $model): array
|
||||
{
|
||||
return [
|
||||
'id' => $model->id,
|
||||
|
|
|
@ -16,17 +16,15 @@ class ApiKeyTransformer extends BaseClientTransformer
|
|||
|
||||
/**
|
||||
* Transform this model into a representation that can be consumed by a client.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function transform(ApiKey $model)
|
||||
public function transform(ApiKey $model): array
|
||||
{
|
||||
return [
|
||||
'identifier' => $model->identifier,
|
||||
'description' => $model->memo,
|
||||
'allowed_ips' => $model->allowed_ips,
|
||||
'last_used_at' => $model->last_used_at ? $model->last_used_at->toIso8601String() : null,
|
||||
'created_at' => $model->created_at->toIso8601String(),
|
||||
'last_used_at' => $model->last_used_at ? $model->last_used_at->toAtomString() : null,
|
||||
'created_at' => $model->created_at->toAtomString(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,10 +11,7 @@ class BackupTransformer extends BaseClientTransformer
|
|||
return Backup::RESOURCE_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function transform(Backup $backup)
|
||||
public function transform(Backup $backup): array
|
||||
{
|
||||
return [
|
||||
'uuid' => $backup->uuid,
|
||||
|
@ -24,8 +21,8 @@ class BackupTransformer extends BaseClientTransformer
|
|||
'ignored_files' => $backup->ignored_files,
|
||||
'checksum' => $backup->checksum,
|
||||
'bytes' => $backup->bytes,
|
||||
'created_at' => $backup->created_at->toIso8601String(),
|
||||
'completed_at' => $backup->completed_at ? $backup->completed_at->toIso8601String() : null,
|
||||
'created_at' => $backup->created_at->toAtomString(),
|
||||
'completed_at' => $backup->completed_at ? $backup->completed_at->toAtomString() : null,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,9 @@
|
|||
namespace Pterodactyl\Transformers\Api\Client;
|
||||
|
||||
use Pterodactyl\Models\Database;
|
||||
use League\Fractal\Resource\Item;
|
||||
use Pterodactyl\Models\Permission;
|
||||
use League\Fractal\Resource\NullResource;
|
||||
use Illuminate\Contracts\Encryption\Encrypter;
|
||||
use Pterodactyl\Contracts\Extensions\HashidsInterface;
|
||||
|
||||
|
@ -11,15 +13,9 @@ class DatabaseTransformer extends BaseClientTransformer
|
|||
{
|
||||
protected array $availableIncludes = ['password'];
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Encryption\Encrypter
|
||||
*/
|
||||
private $encrypter;
|
||||
private Encrypter $encrypter;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Extensions\HashidsInterface
|
||||
*/
|
||||
private $hashids;
|
||||
private HashidsInterface $hashids;
|
||||
|
||||
/**
|
||||
* Handle dependency injection.
|
||||
|
@ -54,10 +50,8 @@ class DatabaseTransformer extends BaseClientTransformer
|
|||
|
||||
/**
|
||||
* Include the database password in the request.
|
||||
*
|
||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||
*/
|
||||
public function includePassword(Database $database)
|
||||
public function includePassword(Database $database): Item|NullResource
|
||||
{
|
||||
if (!$this->request->user()->can(Permission::ACTION_DATABASE_VIEW_PASSWORD, $database->server)) {
|
||||
return $this->null();
|
||||
|
|
|
@ -14,10 +14,7 @@ class EggTransformer extends BaseClientTransformer
|
|||
return Egg::RESOURCE_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function transform(Egg $egg)
|
||||
public function transform(Egg $egg): array
|
||||
{
|
||||
return [
|
||||
'uuid' => $egg->uuid,
|
||||
|
|
|
@ -12,10 +12,7 @@ class EggVariableTransformer extends BaseClientTransformer
|
|||
return EggVariable::RESOURCE_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function transform(EggVariable $variable)
|
||||
public function transform(EggVariable $variable): array
|
||||
{
|
||||
// This guards against someone incorrectly retrieving variables (haha, me) and then passing
|
||||
// them into the transformer and along to the user. Just throw an exception and break the entire
|
||||
|
|
|
@ -9,10 +9,8 @@ class FileObjectTransformer extends BaseClientTransformer
|
|||
{
|
||||
/**
|
||||
* Transform a file object response from the daemon into a standardized response.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function transform(array $item)
|
||||
public function transform(array $item): array
|
||||
{
|
||||
return [
|
||||
'name' => Arr::get($item, 'name'),
|
||||
|
@ -22,8 +20,8 @@ class FileObjectTransformer extends BaseClientTransformer
|
|||
'is_file' => Arr::get($item, 'file', true),
|
||||
'is_symlink' => Arr::get($item, 'symlink', false),
|
||||
'mimetype' => Arr::get($item, 'mime', 'application/octet-stream'),
|
||||
'created_at' => Carbon::parse(Arr::get($item, 'created', ''))->toIso8601String(),
|
||||
'modified_at' => Carbon::parse(Arr::get($item, 'modified', ''))->toIso8601String(),
|
||||
'created_at' => Carbon::parse(Arr::get($item, 'created', ''))->toAtomString(),
|
||||
'modified_at' => Carbon::parse(Arr::get($item, 'modified', ''))->toAtomString(),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace Pterodactyl\Transformers\Api\Client;
|
|||
|
||||
use Pterodactyl\Models\Task;
|
||||
use Pterodactyl\Models\Schedule;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use League\Fractal\Resource\Collection;
|
||||
|
||||
class ScheduleTransformer extends BaseClientTransformer
|
||||
{
|
||||
|
@ -22,10 +22,8 @@ class ScheduleTransformer extends BaseClientTransformer
|
|||
|
||||
/**
|
||||
* Returns a transformed schedule model such that a client can view the information.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function transform(Schedule $model)
|
||||
public function transform(Schedule $model): array
|
||||
{
|
||||
return [
|
||||
'id' => $model->id,
|
||||
|
@ -40,21 +38,19 @@ class ScheduleTransformer extends BaseClientTransformer
|
|||
'is_active' => $model->is_active,
|
||||
'is_processing' => $model->is_processing,
|
||||
'only_when_online' => $model->only_when_online,
|
||||
'last_run_at' => $model->last_run_at ? $model->last_run_at->toIso8601String() : null,
|
||||
'next_run_at' => $model->next_run_at ? $model->next_run_at->toIso8601String() : null,
|
||||
'created_at' => $model->created_at->toIso8601String(),
|
||||
'updated_at' => $model->updated_at->toIso8601String(),
|
||||
'last_run_at' => $model->last_run_at?->toAtomString(),
|
||||
'next_run_at' => $model->next_run_at?->toAtomString(),
|
||||
'created_at' => $model->created_at->toAtomString(),
|
||||
'updated_at' => $model->updated_at->toAtomString(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows attaching the tasks specific to the schedule in the response.
|
||||
*
|
||||
* @return \League\Fractal\Resource\Collection
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeTasks(Schedule $model)
|
||||
public function includeTasks(Schedule $model): Collection
|
||||
{
|
||||
return $this->collection(
|
||||
$model->tasks,
|
||||
|
|
|
@ -5,17 +5,17 @@ namespace Pterodactyl\Transformers\Api\Client;
|
|||
use Pterodactyl\Models\Egg;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Models\Subuser;
|
||||
use League\Fractal\Resource\Item;
|
||||
use Pterodactyl\Models\Allocation;
|
||||
use Pterodactyl\Models\Permission;
|
||||
use Illuminate\Container\Container;
|
||||
use Pterodactyl\Models\EggVariable;
|
||||
use League\Fractal\Resource\Collection;
|
||||
use League\Fractal\Resource\NullResource;
|
||||
use Pterodactyl\Services\Servers\StartupCommandService;
|
||||
|
||||
class ServerTransformer extends BaseClientTransformer
|
||||
{
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected array $defaultIncludes = ['allocations', 'variables'];
|
||||
|
||||
protected array $availableIncludes = ['egg', 'subusers'];
|
||||
|
@ -77,11 +77,9 @@ class ServerTransformer extends BaseClientTransformer
|
|||
/**
|
||||
* Returns the allocations associated with this server.
|
||||
*
|
||||
* @return \League\Fractal\Resource\Collection
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeAllocations(Server $server)
|
||||
public function includeAllocations(Server $server): Collection
|
||||
{
|
||||
$transformer = $this->makeTransformer(AllocationTransformer::class);
|
||||
|
||||
|
@ -104,11 +102,9 @@ class ServerTransformer extends BaseClientTransformer
|
|||
}
|
||||
|
||||
/**
|
||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeVariables(Server $server)
|
||||
public function includeVariables(Server $server): Collection|NullResource
|
||||
{
|
||||
if (!$this->request->user()->can(Permission::ACTION_STARTUP_READ, $server)) {
|
||||
return $this->null();
|
||||
|
@ -124,11 +120,9 @@ class ServerTransformer extends BaseClientTransformer
|
|||
/**
|
||||
* Returns the egg associated with this server.
|
||||
*
|
||||
* @return \League\Fractal\Resource\Item
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeEgg(Server $server)
|
||||
public function includeEgg(Server $server): Item
|
||||
{
|
||||
return $this->item($server->egg, $this->makeTransformer(EggTransformer::class), Egg::RESOURCE_NAME);
|
||||
}
|
||||
|
@ -136,11 +130,9 @@ class ServerTransformer extends BaseClientTransformer
|
|||
/**
|
||||
* Returns the subusers associated with this server.
|
||||
*
|
||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeSubusers(Server $server)
|
||||
public function includeSubusers(Server $server): Collection|NullResource
|
||||
{
|
||||
if (!$this->request->user()->can(Permission::ACTION_USER_READ, $server)) {
|
||||
return $this->null();
|
||||
|
|
|
@ -14,10 +14,8 @@ class StatsTransformer extends BaseClientTransformer
|
|||
/**
|
||||
* Transform stats from the daemon into a result set that can be used in
|
||||
* the client API.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function transform(array $data)
|
||||
public function transform(array $data): array
|
||||
{
|
||||
return [
|
||||
'current_state' => Arr::get($data, 'state', 'stopped'),
|
||||
|
|
|
@ -17,11 +17,9 @@ class SubuserTransformer extends BaseClientTransformer
|
|||
/**
|
||||
* Transforms a subuser into a model that can be shown to a front-end user.
|
||||
*
|
||||
* @return array|void
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function transform(Subuser $model)
|
||||
public function transform(Subuser $model): array
|
||||
{
|
||||
return array_merge(
|
||||
$this->makeTransformer(UserTransformer::class)->transform($model->user),
|
||||
|
|
|
@ -16,10 +16,8 @@ class TaskTransformer extends BaseClientTransformer
|
|||
|
||||
/**
|
||||
* Transforms a schedule's task into a client viewable format.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function transform(Task $model)
|
||||
public function transform(Task $model): array
|
||||
{
|
||||
return [
|
||||
'id' => $model->id,
|
||||
|
@ -29,8 +27,8 @@ class TaskTransformer extends BaseClientTransformer
|
|||
'time_offset' => $model->time_offset,
|
||||
'is_queued' => $model->is_queued,
|
||||
'continue_on_failure' => $model->continue_on_failure,
|
||||
'created_at' => $model->created_at->toIso8601String(),
|
||||
'updated_at' => $model->updated_at->toIso8601String(),
|
||||
'created_at' => $model->created_at->toAtomString(),
|
||||
'updated_at' => $model->updated_at->toAtomString(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ class UserSSHKeyTransformer extends BaseClientTransformer
|
|||
'name' => $model->name,
|
||||
'fingerprint' => $model->fingerprint,
|
||||
'public_key' => $model->public_key,
|
||||
'created_at' => $model->created_at->toIso8601String(),
|
||||
'created_at' => $model->created_at->toAtomString(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,10 +18,8 @@ class UserTransformer extends BaseClientTransformer
|
|||
/**
|
||||
* Transforms a User model into a representation that can be shown to regular
|
||||
* users of the API.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function transform(User $model)
|
||||
public function transform(User $model): array
|
||||
{
|
||||
return [
|
||||
'uuid' => $model->uuid,
|
||||
|
@ -29,7 +27,7 @@ class UserTransformer extends BaseClientTransformer
|
|||
'email' => $model->email,
|
||||
'image' => 'https://gravatar.com/avatar/' . md5(Str::lower($model->email)),
|
||||
'2fa_enabled' => $model->use_totp,
|
||||
'created_at' => $model->created_at->toIso8601String(),
|
||||
'created_at' => $model->created_at->toAtomString(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue