Upgrade to Laravel 9 (#4413)

Co-authored-by: DaneEveritt <dane@daneeveritt.com>
This commit is contained in:
Matthew Penner 2022-10-14 10:59:20 -06:00 committed by GitHub
parent 95e15d2c8a
commit cbcf62086f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
573 changed files with 4387 additions and 9411 deletions

View file

@ -37,10 +37,8 @@ class AdminAcl
/**
* Determine if an API key has permission to perform a specific read/write operation.
*
* @return bool
*/
public static function can(int $permission, int $action = self::READ)
public static function can(int $permission, int $action = self::READ): bool
{
if ($permission & $action) {
return true;
@ -52,10 +50,8 @@ class AdminAcl
/**
* Determine if an API Key model has permission to access a given resource
* at a specific action level.
*
* @return bool
*/
public static function check(ApiKey $key, string $resource, int $action = self::READ)
public static function check(ApiKey $key, string $resource, int $action = self::READ): bool
{
return self::can(data_get($key, self::COLUMN_IDENTIFIER . $resource, self::NONE), $action);
}

View file

@ -4,7 +4,7 @@ namespace Pterodactyl\Services\Activity;
use Ramsey\Uuid\Uuid;
class AcitvityLogBatchService
class ActivityLogBatchService
{
protected int $transaction = 0;
protected ?string $uuid = null;
@ -47,10 +47,8 @@ class AcitvityLogBatchService
/**
* Executes the logic provided within the callback in the scope of an activity
* log batch transaction.
*
* @return mixed
*/
public function transaction(\Closure $callback)
public function transaction(\Closure $callback): mixed
{
$this->start();
$result = $callback($this->uuid());

View file

@ -7,11 +7,11 @@ use Webmozart\Assert\Assert;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use Pterodactyl\Models\ActivityLog;
use Illuminate\Contracts\Auth\Factory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Request;
use Pterodactyl\Models\ActivityLogSubject;
use Illuminate\Database\ConnectionInterface;
use Illuminate\Contracts\Auth\Factory as AuthFactory;
class ActivityLogService
{
@ -19,24 +19,12 @@ class ActivityLogService
protected array $subjects = [];
protected Factory $manager;
protected ConnectionInterface $connection;
protected AcitvityLogBatchService $batch;
protected ActivityLogTargetableService $targetable;
public function __construct(
Factory $manager,
AcitvityLogBatchService $batch,
ActivityLogTargetableService $targetable,
ConnectionInterface $connection
protected AuthFactory $manager,
protected ActivityLogBatchService $batch,
protected ActivityLogTargetableService $targetable,
protected ConnectionInterface $connection
) {
$this->manager = $manager;
$this->batch = $batch;
$this->targetable = $targetable;
$this->connection = $connection;
}
/**
@ -75,11 +63,17 @@ class ActivityLogService
/**
* Sets the subject model instance.
*
* @param \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Model[] $subjects
* @template T extends \Illuminate\Database\Eloquent\Model|\Illuminate\Contracts\Auth\Authenticatable
*
* @param T|T[]|null $subjects
*/
public function subject(...$subjects): self
{
foreach (Arr::wrap($subjects) as $subject) {
if (is_null($subject)) {
continue;
}
foreach ($this->subjects as $entry) {
// If this subject is already tracked in our array of subjects just skip over
// it and move on to the next one in the list.
@ -170,11 +164,9 @@ class ActivityLogService
/**
* Executes the provided callback within the scope of a database transaction
* and will only save the activity log entry if everything else succesfully
* and will only save the activity log entry if everything else successfully
* settles.
*
* @return mixed
*
* @throws \Throwable
*/
public function transaction(\Closure $callback)

View file

@ -8,28 +8,20 @@ use Pterodactyl\Exceptions\Service\Allocation\ServerUsingAllocationException;
class AllocationDeletionService
{
/**
* @var \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface
*/
private $repository;
/**
* AllocationDeletionService constructor.
*/
public function __construct(AllocationRepositoryInterface $repository)
public function __construct(private AllocationRepositoryInterface $repository)
{
$this->repository = $repository;
}
/**
* Delete an allocation from the database only if it does not have a server
* that is actively attached to it.
*
* @return int
*
* @throws \Pterodactyl\Exceptions\Service\Allocation\ServerUsingAllocationException
*/
public function handle(Allocation $allocation)
public function handle(Allocation $allocation): int
{
if (!is_null($allocation->server_id)) {
throw new ServerUsingAllocationException(trans('exceptions.allocations.server_using'));

View file

@ -22,23 +22,11 @@ class AssignmentService
public const PORT_RANGE_LIMIT = 1000;
public const PORT_RANGE_REGEX = '/^(\d{4,5})-(\d{4,5})$/';
/**
* @var \Illuminate\Database\ConnectionInterface
*/
protected $connection;
/**
* @var \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface
*/
protected $repository;
/**
* AssignmentService constructor.
*/
public function __construct(AllocationRepositoryInterface $repository, ConnectionInterface $connection)
public function __construct(protected AllocationRepositoryInterface $repository, protected ConnectionInterface $connection)
{
$this->connection = $connection;
$this->repository = $repository;
}
/**
@ -50,7 +38,7 @@ class AssignmentService
* @throws \Pterodactyl\Exceptions\Service\Allocation\PortOutOfRangeException
* @throws \Pterodactyl\Exceptions\Service\Allocation\TooManyPortsInRangeException
*/
public function handle(Node $node, array $data)
public function handle(Node $node, array $data): void
{
$explode = explode('/', $data['allocation_ip']);
if (count($explode) !== 1) {

View file

@ -10,19 +10,11 @@ use Pterodactyl\Exceptions\Service\Allocation\NoAutoAllocationSpaceAvailableExce
class FindAssignableAllocationService
{
/**
* @var \Pterodactyl\Services\Allocations\AssignmentService
*/
private $service;
/**
* FindAssignableAllocationService constructor.
*
* @param \Pterodactyl\Services\Allocations\AssignmentService $service
*/
public function __construct(AssignmentService $service)
public function __construct(private AssignmentService $service)
{
$this->service = $service;
}
/**
@ -30,15 +22,13 @@ class FindAssignableAllocationService
* no allocation can be found, a new one will be created with a random port between the defined
* range from the configuration.
*
* @return \Pterodactyl\Models\Allocation
*
* @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Pterodactyl\Exceptions\Service\Allocation\CidrOutOfRangeException
* @throws \Pterodactyl\Exceptions\Service\Allocation\InvalidPortMappingException
* @throws \Pterodactyl\Exceptions\Service\Allocation\PortOutOfRangeException
* @throws \Pterodactyl\Exceptions\Service\Allocation\TooManyPortsInRangeException
*/
public function handle(Server $server)
public function handle(Server $server): Allocation
{
if (!config('pterodactyl.client_features.allocations.enabled')) {
throw new AutoAllocationNotEnabledException();

View file

@ -8,37 +8,20 @@ use Pterodactyl\Contracts\Repository\ApiKeyRepositoryInterface;
class KeyCreationService
{
/**
* @var \Illuminate\Contracts\Encryption\Encrypter
*/
private $encrypter;
/**
* @var int
*/
private $keyType = ApiKey::TYPE_NONE;
/**
* @var \Pterodactyl\Contracts\Repository\ApiKeyRepositoryInterface
*/
private $repository;
private int $keyType = ApiKey::TYPE_NONE;
/**
* ApiKeyService constructor.
*/
public function __construct(ApiKeyRepositoryInterface $repository, Encrypter $encrypter)
public function __construct(private ApiKeyRepositoryInterface $repository, private Encrypter $encrypter)
{
$this->encrypter = $encrypter;
$this->repository = $repository;
}
/**
* Set the type of key that should be created. By default an orphaned key will be
* created. These keys cannot be used for anything, and will not render in the UI.
*
* @return \Pterodactyl\Services\Api\KeyCreationService
*/
public function setKeyType(int $type)
public function setKeyType(int $type): self
{
$this->keyType = $type;

View file

@ -7,46 +7,17 @@ use Pterodactyl\Models\Backup;
use GuzzleHttp\Exception\ClientException;
use Illuminate\Database\ConnectionInterface;
use Pterodactyl\Extensions\Backups\BackupManager;
use Pterodactyl\Repositories\Eloquent\BackupRepository;
use Pterodactyl\Repositories\Wings\DaemonBackupRepository;
use Pterodactyl\Exceptions\Service\Backup\BackupLockedException;
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
class DeleteBackupService
{
/**
* @var \Pterodactyl\Repositories\Eloquent\BackupRepository
*/
private $repository;
/**
* @var \Pterodactyl\Repositories\Wings\DaemonBackupRepository
*/
private $daemonBackupRepository;
/**
* @var \Illuminate\Database\ConnectionInterface
*/
private $connection;
/**
* @var \Pterodactyl\Extensions\Backups\BackupManager
*/
private $manager;
/**
* DeleteBackupService constructor.
*/
public function __construct(
ConnectionInterface $connection,
BackupRepository $repository,
BackupManager $manager,
DaemonBackupRepository $daemonBackupRepository
private ConnectionInterface $connection,
private BackupManager $manager,
private DaemonBackupRepository $daemonBackupRepository
) {
$this->repository = $repository;
$this->daemonBackupRepository = $daemonBackupRepository;
$this->connection = $connection;
$this->manager = $manager;
}
/**
@ -55,7 +26,7 @@ class DeleteBackupService
*
* @throws \Throwable
*/
public function handle(Backup $backup)
public function handle(Backup $backup): void
{
// If the backup is marked as failed it can still be deleted, even if locked
// since the UI doesn't allow you to unlock a failed backup in the first place.
@ -79,13 +50,13 @@ class DeleteBackupService
} catch (DaemonConnectionException $exception) {
$previous = $exception->getPrevious();
// Don't fail the request if the Daemon responds with a 404, just assume the backup
// doesn't actually exist and remove it's reference from the Panel as well.
// doesn't actually exist and remove its reference from the Panel as well.
if (!$previous instanceof ClientException || $previous->getResponse()->getStatusCode() !== Response::HTTP_NOT_FOUND) {
throw $exception;
}
}
$this->repository->delete($backup->id);
$backup->delete();
});
}
@ -94,12 +65,12 @@ class DeleteBackupService
*
* @throws \Throwable
*/
protected function deleteFromS3(Backup $backup)
protected function deleteFromS3(Backup $backup): void
{
$this->connection->transaction(function () use ($backup) {
$this->repository->delete($backup->id);
$backup->delete();
/** @var \League\Flysystem\AwsS3v3\AwsS3Adapter $adapter */
/** @var \Pterodactyl\Extensions\Filesystem\S3Filesystem $adapter */
$adapter = $this->manager->adapter(Backup::ADAPTER_AWS_S3);
$adapter->getClient()->deleteObject([

View file

@ -10,23 +10,11 @@ use Pterodactyl\Extensions\Backups\BackupManager;
class DownloadLinkService
{
/**
* @var \Pterodactyl\Extensions\Backups\BackupManager
*/
private $backupManager;
/**
* @var \Pterodactyl\Services\Nodes\NodeJWTService
*/
private $jwtService;
/**
* DownloadLinkService constructor.
*/
public function __construct(BackupManager $backupManager, NodeJWTService $jwtService)
public function __construct(private BackupManager $backupManager, private NodeJWTService $jwtService)
{
$this->backupManager = $backupManager;
$this->jwtService = $jwtService;
}
/**
@ -54,12 +42,10 @@ class DownloadLinkService
/**
* Returns a signed URL that allows us to download a file directly out of a non-public
* S3 bucket by using a signed URL.
*
* @return string
*/
protected function getS3BackupUrl(Backup $backup)
protected function getS3BackupUrl(Backup $backup): string
{
/** @var \League\Flysystem\AwsS3v3\AwsS3Adapter $adapter */
/** @var \Pterodactyl\Extensions\Filesystem\S3Filesystem $adapter */
$adapter = $this->backupManager->adapter(Backup::ADAPTER_AWS_S3);
$request = $adapter->getClient()->createPresignedRequest(

View file

@ -16,65 +16,25 @@ use Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException;
class InitiateBackupService
{
/**
* @var string[]|null
*/
private $ignoredFiles;
private ?array $ignoredFiles;
/**
* @var bool
*/
private $isLocked = false;
/**
* @var \Pterodactyl\Repositories\Eloquent\BackupRepository
*/
private $repository;
/**
* @var \Illuminate\Database\ConnectionInterface
*/
private $connection;
/**
* @var \Pterodactyl\Repositories\Wings\DaemonBackupRepository
*/
private $daemonBackupRepository;
/**
* @var \Pterodactyl\Extensions\Backups\BackupManager
*/
private $backupManager;
/**
* @var \Pterodactyl\Services\Backups\DeleteBackupService
*/
private $deleteBackupService;
private bool $isLocked = false;
/**
* InitiateBackupService constructor.
*
* @param \Pterodactyl\Services\Backups\DeleteBackupService $deleteBackupService
*/
public function __construct(
BackupRepository $repository,
ConnectionInterface $connection,
DaemonBackupRepository $daemonBackupRepository,
DeleteBackupService $deleteBackupService,
BackupManager $backupManager
private BackupRepository $repository,
private ConnectionInterface $connection,
private DaemonBackupRepository $daemonBackupRepository,
private DeleteBackupService $deleteBackupService,
private BackupManager $backupManager
) {
$this->repository = $repository;
$this->connection = $connection;
$this->daemonBackupRepository = $daemonBackupRepository;
$this->backupManager = $backupManager;
$this->deleteBackupService = $deleteBackupService;
}
/**
* Set if the backup should be locked once it is created which will prevent
* its deletion by users or automated system processes.
*
* @return $this
*/
public function setIsLocked(bool $isLocked): self
{
@ -87,10 +47,8 @@ class InitiateBackupService
* Sets the files to be ignored by this backup.
*
* @param string[]|null $ignored
*
* @return $this
*/
public function setIgnoredFiles(?array $ignored)
public function setIgnoredFiles(?array $ignored): self
{
if (is_array($ignored)) {
foreach ($ignored as $value) {

View file

@ -25,49 +25,20 @@ class DatabaseManagementService
*/
private const MATCH_NAME_REGEX = '/^(s[\d]+_)(.*)$/';
/**
* @var \Illuminate\Database\ConnectionInterface
*/
private $connection;
/**
* @var \Pterodactyl\Extensions\DynamicDatabaseConnection
*/
private $dynamic;
/**
* @var \Illuminate\Contracts\Encryption\Encrypter
*/
private $encrypter;
/**
* @var \Pterodactyl\Repositories\Eloquent\DatabaseRepository
*/
private $repository;
/**
* Determines if the service should validate the user's ability to create an additional
* database for this server. In almost all cases this should be true, but to keep things
* flexible you can also set it to false and create more databases than the server is
* allocated.
*
* @var bool
*/
protected $validateDatabaseLimit = true;
protected bool $validateDatabaseLimit = true;
/**
* CreationService constructor.
*/
public function __construct(
ConnectionInterface $connection,
DynamicDatabaseConnection $dynamic,
DatabaseRepository $repository,
Encrypter $encrypter
protected ConnectionInterface $connection,
protected DynamicDatabaseConnection $dynamic,
protected Encrypter $encrypter,
protected DatabaseRepository $repository
) {
$this->connection = $connection;
$this->dynamic = $dynamic;
$this->encrypter = $encrypter;
$this->repository = $repository;
}
/**
@ -82,10 +53,8 @@ class DatabaseManagementService
}
/**
* Set wether or not this class should validate that the server has enough slots
* Set whether this class should validate that the server has enough slots
* left before creating the new database.
*
* @return $this
*/
public function setValidateDatabaseLimit(bool $validate): self
{
@ -97,13 +66,11 @@ class DatabaseManagementService
/**
* Create a new database that is linked to a specific host.
*
* @return \Pterodactyl\Models\Database
*
* @throws \Throwable
* @throws \Pterodactyl\Exceptions\Service\Database\TooManyDatabasesException
* @throws \Pterodactyl\Exceptions\Service\Database\DatabaseClientFeatureNotEnabledException
*/
public function create(Server $server, array $data)
public function create(Server $server, array $data): Database
{
if (!config('pterodactyl.client_features.databases.enabled')) {
throw new DatabaseClientFeatureNotEnabledException();
@ -169,11 +136,9 @@ class DatabaseManagementService
/**
* Delete a database from the given host server.
*
* @return bool|null
*
* @throws \Exception
*/
public function delete(Database $database)
public function delete(Database $database): ?bool
{
$this->dynamic->set('dynamic', $database->database_host_id);

View file

@ -11,49 +11,23 @@ use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface;
class DatabasePasswordService
{
/**
* @var \Illuminate\Database\ConnectionInterface
*/
private $connection;
/**
* @var \Pterodactyl\Extensions\DynamicDatabaseConnection
*/
private $dynamic;
/**
* @var \Illuminate\Contracts\Encryption\Encrypter
*/
private $encrypter;
/**
* @var \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface
*/
private $repository;
/**
* DatabasePasswordService constructor.
*/
public function __construct(
ConnectionInterface $connection,
DatabaseRepositoryInterface $repository,
DynamicDatabaseConnection $dynamic,
Encrypter $encrypter
private ConnectionInterface $connection,
private DynamicDatabaseConnection $dynamic,
private Encrypter $encrypter,
private DatabaseRepositoryInterface $repository
) {
$this->connection = $connection;
$this->dynamic = $dynamic;
$this->encrypter = $encrypter;
$this->repository = $repository;
}
/**
* Updates a password for a given database.
*
* @param \Pterodactyl\Models\Database|int $database
*
* @throws \Throwable
*/
public function handle(Database $database): string
public function handle(Database|int $database): string
{
$password = Utilities::randomStringWithSpecialCharacters(24);

View file

@ -11,18 +11,10 @@ use Pterodactyl\Exceptions\Service\Database\NoSuitableDatabaseHostException;
class DeployServerDatabaseService
{
/**
* @var \Pterodactyl\Services\Databases\DatabaseManagementService
* DeployServerDatabaseService constructor.
*/
private $managementService;
/**
* ServerDatabaseCreationService constructor.
*
* @param \Pterodactyl\Services\Databases\DatabaseManagementService $managementService
*/
public function __construct(DatabaseManagementService $managementService)
public function __construct(private DatabaseManagementService $managementService)
{
$this->managementService = $managementService;
}
/**

View file

@ -11,46 +11,16 @@ use Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface;
class HostCreationService
{
/**
* @var \Illuminate\Database\ConnectionInterface
*/
private $connection;
/**
* @var \Illuminate\Database\DatabaseManager
*/
private $databaseManager;
/**
* @var \Pterodactyl\Extensions\DynamicDatabaseConnection
*/
private $dynamic;
/**
* @var \Illuminate\Contracts\Encryption\Encrypter
*/
private $encrypter;
/**
* @var \Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface
*/
private $repository;
/**
* HostCreationService constructor.
*/
public function __construct(
ConnectionInterface $connection,
DatabaseManager $databaseManager,
DatabaseHostRepositoryInterface $repository,
DynamicDatabaseConnection $dynamic,
Encrypter $encrypter
private ConnectionInterface $connection,
private DatabaseManager $databaseManager,
private DynamicDatabaseConnection $dynamic,
private Encrypter $encrypter,
private DatabaseHostRepositoryInterface $repository
) {
$this->connection = $connection;
$this->databaseManager = $databaseManager;
$this->dynamic = $dynamic;
$this->encrypter = $encrypter;
$this->repository = $repository;
}
/**

View file

@ -8,25 +8,13 @@ use Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface;
class HostDeletionService
{
/**
* @var \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface
*/
private $databaseRepository;
/**
* @var \Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface
*/
private $repository;
/**
* HostDeletionService constructor.
*/
public function __construct(
DatabaseRepositoryInterface $databaseRepository,
DatabaseHostRepositoryInterface $repository
private DatabaseRepositoryInterface $databaseRepository,
private DatabaseHostRepositoryInterface $repository
) {
$this->databaseRepository = $databaseRepository;
$this->repository = $repository;
}
/**

View file

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Services\Databases\Hosts;
@ -19,45 +12,15 @@ use Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface;
class HostUpdateService
{
/**
* @var \Illuminate\Database\ConnectionInterface
*/
private $connection;
/**
* @var \Illuminate\Database\DatabaseManager
*/
private $databaseManager;
/**
* @var \Pterodactyl\Extensions\DynamicDatabaseConnection
*/
private $dynamic;
/**
* @var \Illuminate\Contracts\Encryption\Encrypter
*/
private $encrypter;
/**
* @var \Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface
*/
private $repository;
/**
* DatabaseHostService constructor.
* HostUpdateService constructor.
*/
public function __construct(
ConnectionInterface $connection,
DatabaseManager $databaseManager,
DatabaseHostRepositoryInterface $repository,
DynamicDatabaseConnection $dynamic,
Encrypter $encrypter
private ConnectionInterface $connection,
private DatabaseManager $databaseManager,
private DynamicDatabaseConnection $dynamic,
private Encrypter $encrypter,
private DatabaseHostRepositoryInterface $repository
) {
$this->connection = $connection;
$this->databaseManager = $databaseManager;
$this->dynamic = $dynamic;
$this->encrypter = $encrypter;
$this->repository = $repository;
}
/**

View file

@ -10,42 +10,25 @@ use Pterodactyl\Exceptions\Service\Deployment\NoViableAllocationException;
class AllocationSelectionService
{
/**
* @var \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface
*/
private $repository;
protected bool $dedicated = false;
/**
* @var bool
*/
protected $dedicated = false;
protected array $nodes = [];
/**
* @var array
*/
protected $nodes = [];
/**
* @var array
*/
protected $ports = [];
protected array $ports = [];
/**
* AllocationSelectionService constructor.
*/
public function __construct(AllocationRepositoryInterface $repository)
public function __construct(private AllocationRepositoryInterface $repository)
{
$this->repository = $repository;
}
/**
* Toggle if the selected allocation should be the only allocation belonging
* to the given IP address. If true an allocation will not be selected if an IP
* already has another server set to use on if its allocations.
*
* @return $this
*/
public function setDedicated(bool $dedicated)
public function setDedicated(bool $dedicated): self
{
$this->dedicated = $dedicated;
@ -55,10 +38,8 @@ class AllocationSelectionService
/**
* A list of node IDs that should be used when selecting an allocation. If empty, all
* nodes will be used to filter with.
*
* @return $this
*/
public function setNodes(array $nodes)
public function setNodes(array $nodes): self
{
$this->nodes = $nodes;
@ -70,11 +51,9 @@ class AllocationSelectionService
* empty, all ports will be considered when finding an allocation. If set, only ports appearing
* in the array or range will be used.
*
* @return $this
*
* @throws \Pterodactyl\Exceptions\DisplayException
*/
public function setPorts(array $ports)
public function setPorts(array $ports): self
{
$stored = [];
foreach ($ports as $port) {

View file

@ -4,29 +4,18 @@ namespace Pterodactyl\Services\Deployment;
use Pterodactyl\Models\Node;
use Webmozart\Assert\Assert;
use Illuminate\Support\Collection;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Pterodactyl\Exceptions\Service\Deployment\NoViableNodeException;
class FindViableNodesService
{
/**
* @var array
*/
protected $locations = [];
/**
* @var int
*/
protected $disk;
/**
* @var int
*/
protected $memory;
protected array $locations = [];
protected ?int $disk = null;
protected ?int $memory = null;
/**
* Set the locations that should be searched through to locate available nodes.
*
* @return $this
*/
public function setLocations(array $locations): self
{
@ -41,8 +30,6 @@ class FindViableNodesService
* Set the amount of disk that will be used by the server being created. Nodes will be
* filtered out if they do not have enough available free disk space for this server
* to be placed on.
*
* @return $this
*/
public function setDisk(int $disk): self
{
@ -54,8 +41,6 @@ class FindViableNodesService
/**
* Set the amount of memory that this server will be using. As with disk space, nodes that
* do not have enough free memory will be filtered out.
*
* @return $this
*/
public function setMemory(int $memory): self
{
@ -79,11 +64,9 @@ class FindViableNodesService
* If "null" is provided as the value no pagination will
* be used.
*
* @return \Illuminate\Support\Collection|\Illuminate\Contracts\Pagination\LengthAwarePaginator
*
* @throws \Pterodactyl\Exceptions\Service\Deployment\NoViableNodeException
*/
public function handle(int $perPage = null, int $page = null)
public function handle(int $perPage = null, int $page = null): LengthAwarePaginator|Collection
{
Assert::integer($this->disk, 'Disk space must be an int, got %s');
Assert::integer($this->memory, 'Memory usage must be an int, got %s');

View file

@ -9,17 +9,11 @@ use Pterodactyl\Services\Servers\ServerConfigurationStructureService;
class EggConfigurationService
{
/**
* @var \Pterodactyl\Services\Servers\ServerConfigurationStructureService
*/
private $configurationStructureService;
/**
* EggConfigurationService constructor.
*/
public function __construct(ServerConfigurationStructureService $configurationStructureService)
public function __construct(private ServerConfigurationStructureService $configurationStructureService)
{
$this->configurationStructureService = $configurationStructureService;
}
/**
@ -41,10 +35,8 @@ class EggConfigurationService
/**
* Convert the "done" variable into an array if it is not currently one.
*
* @return array
*/
protected function convertStartupToNewFormat(array $startup)
protected function convertStartupToNewFormat(array $startup): array
{
$done = Arr::get($startup, 'done');
@ -85,10 +77,7 @@ class EggConfigurationService
];
}
/**
* @return array
*/
protected function replacePlaceholders(Server $server, object $configs)
protected function replacePlaceholders(Server $server, object $configs): array
{
// Get the legacy configuration structure for the server so that we
// can property map the egg placeholders to values.
@ -161,20 +150,15 @@ class EggConfigurationService
case 'env.SERVER_PORT':
$replace = 'server.build.default.port';
break;
// By default we don't need to change anything, only if we ended up matching a specific legacy item.
default:
// By default, we don't need to change anything, only if we ended up matching a specific legacy item.
$replace = $key;
}
return str_replace("{{{$key}}}", "{{{$replace}}}", $value);
}
/**
* @param mixed $value
*
* @return mixed|null
*/
protected function matchAndReplaceKeys($value, array $structure)
protected function matchAndReplaceKeys(mixed $value, array $structure): mixed
{
preg_match_all('/{{(?<key>[\w.-]*)}}/', $value, $matches);
@ -229,12 +213,8 @@ class EggConfigurationService
* Iterates over a set of "find" values for a given file in the parser configuration. If
* the value of the line match is something iterable, continue iterating, otherwise perform
* a match & replace.
*
* @param mixed $data
*
* @return mixed
*/
private function iterate($data, array $structure)
private function iterate(mixed $data, array $structure): mixed
{
if (!is_iterable($data) && !is_object($data)) {
return $data;

View file

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Services\Eggs;
@ -18,23 +11,11 @@ use Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException;
// When a mommy and a daddy pterodactyl really like each other...
class EggCreationService
{
/**
* @var \Illuminate\Contracts\Config\Repository
*/
protected $config;
/**
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface
*/
protected $repository;
/**
* EggCreationService constructor.
*/
public function __construct(ConfigRepository $config, EggRepositoryInterface $repository)
public function __construct(private ConfigRepository $config, private EggRepositoryInterface $repository)
{
$this->config = $config;
$this->repository = $repository;
}
/**

View file

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Services\Eggs;
@ -16,25 +9,13 @@ use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
class EggDeletionService
{
/**
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface
*/
protected $repository;
/**
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
*/
protected $serverRepository;
/**
* EggDeletionService constructor.
*/
public function __construct(
ServerRepositoryInterface $serverRepository,
EggRepositoryInterface $repository
protected ServerRepositoryInterface $serverRepository,
protected EggRepositoryInterface $repository
) {
$this->repository = $repository;
$this->serverRepository = $serverRepository;
}
/**

View file

@ -13,6 +13,7 @@ class EggParserService
/**
* Takes an uploaded file and parses out the egg configuration from within.
*
* @throws \JsonException
* @throws \Pterodactyl\Exceptions\Service\InvalidFileUploadException
*/
public function handle(UploadedFile $file): array

View file

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Services\Eggs;
@ -15,17 +8,11 @@ use Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException;
class EggUpdateService
{
/**
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface
*/
protected $repository;
/**
* EggUpdateService constructor.
*/
public function __construct(EggRepositoryInterface $repository)
public function __construct(protected EggRepositoryInterface $repository)
{
$this->repository = $repository;
}
/**
@ -35,7 +22,7 @@ class EggUpdateService
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException
*/
public function handle(Egg $egg, array $data)
public function handle(Egg $egg, array $data): void
{
if (!is_null(array_get($data, 'config_from'))) {
$results = $this->repository->findCountWhere([

View file

@ -8,29 +8,21 @@ use Pterodactyl\Exceptions\Service\Egg\InvalidCopyFromException;
class InstallScriptService
{
/**
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface
*/
protected $repository;
/**
* InstallScriptService constructor.
*/
public function __construct(EggRepositoryInterface $repository)
public function __construct(protected EggRepositoryInterface $repository)
{
$this->repository = $repository;
}
/**
* Modify the install script for a given Egg.
*
* @param int|\Pterodactyl\Models\Egg $egg
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Pterodactyl\Exceptions\Service\Egg\InvalidCopyFromException
*/
public function handle(Egg $egg, array $data)
public function handle(Egg $egg, array $data): void
{
if (!is_null(array_get($data, 'copy_script_from'))) {
if (!$this->repository->isCopyableScript(array_get($data, 'copy_script_from'), $egg->nest_id)) {

View file

@ -10,17 +10,11 @@ use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
class EggExporterService
{
/**
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface
*/
protected $repository;
/**
* EggExporterService constructor.
*/
public function __construct(EggRepositoryInterface $repository)
public function __construct(protected EggRepositoryInterface $repository)
{
$this->repository = $repository;
}
/**
@ -38,7 +32,7 @@ class EggExporterService
'version' => Egg::EXPORT_VERSION,
'update_url' => $egg->update_url,
],
'exported_at' => Carbon::now()->toIso8601String(),
'exported_at' => Carbon::now()->toAtomString(),
'name' => $egg->name,
'author' => $egg->author,
'description' => $egg->description,

View file

@ -13,14 +13,8 @@ use Pterodactyl\Services\Eggs\EggParserService;
class EggImporterService
{
protected ConnectionInterface $connection;
protected EggParserService $parser;
public function __construct(ConnectionInterface $connection, EggParserService $parser)
public function __construct(protected ConnectionInterface $connection, protected EggParserService $parser)
{
$this->connection = $connection;
$this->parser = $parser;
}
/**

View file

@ -11,17 +11,11 @@ use Pterodactyl\Services\Eggs\EggParserService;
class EggUpdateImporterService
{
protected ConnectionInterface $connection;
protected EggParserService $parser;
/**
* EggUpdateImporterService constructor.
*/
public function __construct(ConnectionInterface $connection, EggParserService $parser)
public function __construct(protected ConnectionInterface $connection, protected EggParserService $parser)
{
$this->connection = $connection;
$this->parser = $parser;
}
/**

View file

@ -3,8 +3,8 @@
namespace Pterodactyl\Services\Eggs\Variables;
use Pterodactyl\Models\EggVariable;
use Illuminate\Contracts\Validation\Factory;
use Pterodactyl\Traits\Services\ValidatesValidationRules;
use Illuminate\Contracts\Validation\Factory as ValidationFactory;
use Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface;
use Pterodactyl\Exceptions\Service\Egg\Variable\ReservedVariableNameException;
@ -12,30 +12,18 @@ class VariableCreationService
{
use ValidatesValidationRules;
/**
* @var \Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface
*/
private $repository;
/**
* @var \Illuminate\Contracts\Validation\Factory
*/
private $validator;
/**
* VariableCreationService constructor.
*/
public function __construct(EggVariableRepositoryInterface $repository, Factory $validator)
public function __construct(private EggVariableRepositoryInterface $repository, private ValidationFactory $validator)
{
$this->repository = $repository;
$this->validator = $validator;
}
/**
* Return the validation factory instance to be used by rule validation
* checking in the trait.
*/
protected function getValidator(): Factory
protected function getValidator(): ValidationFactory
{
return $this->validator;
}

View file

@ -4,9 +4,9 @@ namespace Pterodactyl\Services\Eggs\Variables;
use Illuminate\Support\Str;
use Pterodactyl\Models\EggVariable;
use Illuminate\Contracts\Validation\Factory;
use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Traits\Services\ValidatesValidationRules;
use Illuminate\Contracts\Validation\Factory as ValidationFactory;
use Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface;
use Pterodactyl\Exceptions\Service\Egg\Variable\ReservedVariableNameException;
@ -14,30 +14,18 @@ class VariableUpdateService
{
use ValidatesValidationRules;
/**
* @var \Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface
*/
private $repository;
/**
* @var \Illuminate\Contracts\Validation\Factory
*/
private $validator;
/**
* VariableUpdateService constructor.
*/
public function __construct(EggVariableRepositoryInterface $repository, Factory $validator)
public function __construct(private EggVariableRepositoryInterface $repository, private ValidationFactory $validator)
{
$this->repository = $repository;
$this->validator = $validator;
}
/**
* Return the validation factory instance to be used by rule validation
* checking in the trait.
*/
protected function getValidator(): Factory
protected function getValidator(): ValidationFactory
{
return $this->validator;
}
@ -45,14 +33,12 @@ class VariableUpdateService
/**
* Update a specific egg variable.
*
* @return mixed
*
* @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Pterodactyl\Exceptions\Service\Egg\Variable\ReservedVariableNameException
*/
public function handle(EggVariable $variable, array $data)
public function handle(EggVariable $variable, array $data): mixed
{
if (!is_null(array_get($data, 'env_variable'))) {
if (in_array(strtoupper(array_get($data, 'env_variable')), explode(',', EggVariable::RESERVED_ENV_NAMES))) {

View file

@ -1,8 +0,0 @@
<?php
/*
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/

View file

@ -4,7 +4,7 @@ namespace Pterodactyl\Services\Helpers;
use Illuminate\Support\Arr;
use Illuminate\Filesystem\FilesystemManager;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\Filesystem\Filesystem;
class AssetHashService
{
@ -13,34 +13,20 @@ class AssetHashService
*/
public const MANIFEST_PATH = './assets/manifest.json';
/**
* @var \Illuminate\Contracts\Filesystem\Filesystem
*/
private $filesystem;
private Filesystem $filesystem;
/**
* @var \Illuminate\Contracts\Foundation\Application
*/
private $application;
/**
* @var array|null
*/
protected static $manifest;
protected static mixed $manifest;
/**
* AssetHashService constructor.
*/
public function __construct(Application $application, FilesystemManager $filesystem)
public function __construct(FilesystemManager $filesystem)
{
$this->application = $application;
$this->filesystem = $filesystem->createLocalDriver(['root' => public_path()]);
}
/**
* Modify a URL to append the asset hash.
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
public function url(string $resource): string
{
@ -52,8 +38,6 @@ class AssetHashService
/**
* Return the data integrity hash for a resource.
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
public function integrity(string $resource): string
{
@ -65,8 +49,6 @@ class AssetHashService
/**
* Return a built CSS import using the provided URL.
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
public function css(string $resource): string
{
@ -92,8 +74,6 @@ class AssetHashService
/**
* Return a built JS import using the provided URL.
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
public function js(string $resource): string
{
@ -116,8 +96,6 @@ class AssetHashService
/**
* Get the asset manifest and store it in the cache for quicker lookups.
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
protected function manifest(): array
{

View file

@ -13,98 +13,68 @@ class SoftwareVersionService
{
public const VERSION_CACHE_KEY = 'pterodactyl:versioning_data';
/**
* @var array
*/
private static $result;
/**
* @var \Illuminate\Contracts\Cache\Repository
*/
protected $cache;
/**
* @var \GuzzleHttp\Client
*/
protected $client;
private static array $result;
/**
* SoftwareVersionService constructor.
*/
public function __construct(
CacheRepository $cache,
Client $client
protected CacheRepository $cache,
protected Client $client
) {
$this->cache = $cache;
$this->client = $client;
self::$result = $this->cacheVersionData();
}
/**
* Get the latest version of the panel from the CDN servers.
*
* @return string
*/
public function getPanel()
public function getPanel(): string
{
return Arr::get(self::$result, 'panel') ?? 'error';
}
/**
* Get the latest version of the daemon from the CDN servers.
*
* @return string
*/
public function getDaemon()
public function getDaemon(): string
{
return Arr::get(self::$result, 'wings') ?? 'error';
}
/**
* Get the URL to the discord server.
*
* @return string
*/
public function getDiscord()
public function getDiscord(): string
{
return Arr::get(self::$result, 'discord') ?? 'https://pterodactyl.io/discord';
}
/**
* Get the URL for donations.
*
* @return string
*/
public function getDonations()
public function getDonations(): string
{
return Arr::get(self::$result, 'donations') ?? 'https://paypal.me/PterodactylSoftware';
return Arr::get(self::$result, 'donations') ?? 'https://github.com/sponsors/matthewpi';
}
/**
* Determine if the current version of the panel is the latest.
*
* @return bool
*/
public function isLatestPanel()
public function isLatestPanel(): bool
{
if (config()->get('app.version') === 'canary') {
if (config('app.version') === 'canary') {
return true;
}
return version_compare(config()->get('app.version'), $this->getPanel()) >= 0;
return version_compare(config('app.version'), $this->getPanel()) >= 0;
}
/**
* Determine if a passed daemon version string is the latest.
*
* @param string $version
*
* @return bool
*/
public function isLatestDaemon($version)
public function isLatestDaemon(string $version): bool
{
if ($version === '0.0.0-canary') {
if ($version === 'develop') {
return true;
}
@ -113,21 +83,19 @@ class SoftwareVersionService
/**
* Keeps the versioning cache up-to-date with the latest results from the CDN.
*
* @return array
*/
protected function cacheVersionData()
protected function cacheVersionData(): array
{
return $this->cache->remember(self::VERSION_CACHE_KEY, CarbonImmutable::now()->addMinutes(config()->get('pterodactyl.cdn.cache_time', 60)), function () {
return $this->cache->remember(self::VERSION_CACHE_KEY, CarbonImmutable::now()->addMinutes(config('pterodactyl.cdn.cache_time', 60)), function () {
try {
$response = $this->client->request('GET', config()->get('pterodactyl.cdn.url'));
$response = $this->client->request('GET', config('pterodactyl.cdn.url'));
if ($response->getStatusCode() === 200) {
return json_decode($response->getBody(), true);
}
throw new CdnVersionFetchingException();
} catch (Exception $exception) {
} catch (Exception) {
return [];
}
});

View file

@ -1,39 +1,25 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Services\Locations;
use Pterodactyl\Models\Location;
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
class LocationCreationService
{
/**
* @var \Pterodactyl\Contracts\Repository\LocationRepositoryInterface
*/
protected $repository;
/**
* LocationCreationService constructor.
*/
public function __construct(LocationRepositoryInterface $repository)
public function __construct(protected LocationRepositoryInterface $repository)
{
$this->repository = $repository;
}
/**
* Create a new location.
*
* @return \Pterodactyl\Models\Location
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
*/
public function handle(array $data)
public function handle(array $data): Location
{
return $this->repository->create($data);
}

View file

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Services\Locations;
@ -17,37 +10,21 @@ use Pterodactyl\Exceptions\Service\Location\HasActiveNodesException;
class LocationDeletionService
{
/**
* @var \Pterodactyl\Contracts\Repository\NodeRepositoryInterface
*/
protected $nodeRepository;
/**
* @var \Pterodactyl\Contracts\Repository\LocationRepositoryInterface
*/
protected $repository;
/**
* LocationDeletionService constructor.
*/
public function __construct(
LocationRepositoryInterface $repository,
NodeRepositoryInterface $nodeRepository
protected LocationRepositoryInterface $repository,
protected NodeRepositoryInterface $nodeRepository
) {
$this->nodeRepository = $nodeRepository;
$this->repository = $repository;
}
/**
* Delete an existing location.
*
* @param int|\Pterodactyl\Models\Location $location
*
* @return int|null
*
* @throws \Pterodactyl\Exceptions\Service\Location\HasActiveNodesException
*/
public function handle($location)
public function handle(Location|int $location): ?int
{
$location = ($location instanceof Location) ? $location->id : $location;

View file

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Services\Locations;
@ -14,30 +7,20 @@ use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
class LocationUpdateService
{
/**
* @var \Pterodactyl\Contracts\Repository\LocationRepositoryInterface
*/
protected $repository;
/**
* LocationUpdateService constructor.
*/
public function __construct(LocationRepositoryInterface $repository)
public function __construct(protected LocationRepositoryInterface $repository)
{
$this->repository = $repository;
}
/**
* Update an existing location.
*
* @param int|\Pterodactyl\Models\Location $location
*
* @return \Pterodactyl\Models\Location
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function handle($location, array $data)
public function handle(Location|int $location, array $data): Location
{
$location = ($location instanceof Location) ? $location->id : $location;

View file

@ -9,23 +9,11 @@ use Illuminate\Contracts\Config\Repository as ConfigRepository;
class NestCreationService
{
/**
* @var \Illuminate\Contracts\Config\Repository
*/
private $config;
/**
* @var \Pterodactyl\Contracts\Repository\NestRepositoryInterface
*/
private $repository;
/**
* NestCreationService constructor.
*/
public function __construct(ConfigRepository $config, NestRepositoryInterface $repository)
public function __construct(private ConfigRepository $config, private NestRepositoryInterface $repository)
{
$this->config = $config;
$this->repository = $repository;
}
/**

View file

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Services\Nests;
@ -15,25 +8,13 @@ use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
class NestDeletionService
{
/**
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
*/
protected $serverRepository;
/**
* @var \Pterodactyl\Contracts\Repository\NestRepositoryInterface
*/
protected $repository;
/**
* NestDeletionService constructor.
*/
public function __construct(
ServerRepositoryInterface $serverRepository,
NestRepositoryInterface $repository
protected ServerRepositoryInterface $serverRepository,
protected NestRepositoryInterface $repository
) {
$this->serverRepository = $serverRepository;
$this->repository = $repository;
}
/**

View file

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Services\Nests;
@ -13,17 +6,11 @@ use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
class NestUpdateService
{
/**
* @var \Pterodactyl\Contracts\Repository\NestRepositoryInterface
*/
protected $repository;
/**
* NestUpdateService constructor.
*/
public function __construct(NestRepositoryInterface $repository)
public function __construct(protected NestRepositoryInterface $repository)
{
$this->repository = $repository;
}
/**
@ -32,7 +19,7 @@ class NestUpdateService
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function handle(int $nest, array $data)
public function handle(int $nest, array $data): void
{
if (!is_null(array_get($data, 'author'))) {
unset($data['author']);

View file

@ -11,32 +11,18 @@ use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
class NodeCreationService
{
/**
* @var \Pterodactyl\Contracts\Repository\NodeRepositoryInterface
* NodeCreationService constructor.
*/
protected $repository;
/**
* @var \Illuminate\Contracts\Encryption\Encrypter
*/
private $encrypter;
/**
* CreationService constructor.
*/
public function __construct(Encrypter $encrypter, NodeRepositoryInterface $repository)
public function __construct(private Encrypter $encrypter, protected NodeRepositoryInterface $repository)
{
$this->repository = $repository;
$this->encrypter = $encrypter;
}
/**
* Create a new node on the panel.
*
* @return \Pterodactyl\Models\Node
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
*/
public function handle(array $data)
public function handle(array $data): Node
{
$data['uuid'] = Uuid::uuid4()->toString();
$data['daemon_token'] = $this->encrypter->encrypt(Str::random(Node::DAEMON_TOKEN_LENGTH));

View file

@ -1,13 +1,5 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Services\Nodes;
use Pterodactyl\Models\Node;
@ -19,43 +11,21 @@ use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
class NodeDeletionService
{
/**
* @var \Pterodactyl\Contracts\Repository\NodeRepositoryInterface
*/
protected $repository;
/**
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
*/
protected $serverRepository;
/**
* @var \Illuminate\Contracts\Translation\Translator
*/
protected $translator;
/**
* DeletionService constructor.
* NodeDeletionService constructor.
*/
public function __construct(
NodeRepositoryInterface $repository,
ServerRepositoryInterface $serverRepository,
Translator $translator
protected NodeRepositoryInterface $repository,
protected ServerRepositoryInterface $serverRepository,
protected Translator $translator
) {
$this->repository = $repository;
$this->serverRepository = $serverRepository;
$this->translator = $translator;
}
/**
* Delete a node from the panel if no servers are attached to it.
*
* @param int|\Pterodactyl\Models\Node $node
*
* @return bool|null
*
* @throws \Pterodactyl\Exceptions\Service\HasActiveServersException
*/
public function handle($node)
public function handle(int|Node $node): int
{
if ($node instanceof Node) {
$node = $node->id;

View file

@ -7,6 +7,7 @@ use Carbon\CarbonImmutable;
use Illuminate\Support\Str;
use Pterodactyl\Models\Node;
use Pterodactyl\Models\User;
use Lcobucci\JWT\Token\Plain;
use Lcobucci\JWT\Configuration;
use Lcobucci\JWT\Signer\Hmac\Sha256;
use Lcobucci\JWT\Signer\Key\InMemory;
@ -18,19 +19,14 @@ class NodeJWTService
private ?User $user = null;
/**
* @var \DateTimeImmutable|null
*/
private $expiresAt;
private ?DateTimeImmutable $expiresAt;
private ?string $subject = null;
/**
* Set the claims to include in this JWT.
*
* @return $this
*/
public function setClaims(array $claims)
public function setClaims(array $claims): self
{
$this->claims = $claims;
@ -48,20 +44,14 @@ class NodeJWTService
return $this;
}
/**
* @return $this
*/
public function setExpiresAt(DateTimeImmutable $date)
public function setExpiresAt(DateTimeImmutable $date): self
{
$this->expiresAt = $date;
return $this;
}
/**
* @return $this
*/
public function setSubject(string $subject)
public function setSubject(string $subject): self
{
$this->subject = $subject;
@ -70,12 +60,8 @@ class NodeJWTService
/**
* Generate a new JWT for a given node.
*
* @param string|null $identifiedBy
*
* @return \Lcobucci\JWT\Token\Plain
*/
public function handle(Node $node, string $identifiedBy, string $algo = 'md5')
public function handle(Node $node, ?string $identifiedBy, string $algo = 'md5'): Plain
{
$identifier = hash($algo, $identifiedBy);
$config = Configuration::forSymmetricSigner(new Sha256(), InMemory::plainText($node->getDecryptedKey()));
@ -112,7 +98,7 @@ class NodeJWTService
}
return $builder
->withClaim('unique_id', Str::random(16))
->withClaim('unique_id', Str::random())
->getToken($config->signer(), $config->signingKey());
}
}

View file

@ -15,48 +15,22 @@ use Pterodactyl\Exceptions\Service\Node\ConfigurationNotPersistedException;
class NodeUpdateService
{
/**
* @var \Illuminate\Database\ConnectionInterface
*/
private $connection;
/**
* @var \Pterodactyl\Repositories\Wings\DaemonConfigurationRepository
*/
private $configurationRepository;
/**
* @var \Illuminate\Contracts\Encryption\Encrypter
*/
private $encrypter;
/**
* @var \Pterodactyl\Repositories\Eloquent\NodeRepository
*/
private $repository;
/**
* UpdateService constructor.
* NodeUpdateService constructor.
*/
public function __construct(
ConnectionInterface $connection,
Encrypter $encrypter,
DaemonConfigurationRepository $configurationRepository,
NodeRepository $repository
private ConnectionInterface $connection,
private DaemonConfigurationRepository $configurationRepository,
private Encrypter $encrypter,
private NodeRepository $repository
) {
$this->connection = $connection;
$this->configurationRepository = $configurationRepository;
$this->encrypter = $encrypter;
$this->repository = $repository;
}
/**
* Update the configuration values for a given node on the machine.
*
* @return \Pterodactyl\Models\Node
*
* @throws \Throwable
*/
public function handle(Node $node, array $data, bool $resetToken = false)
public function handle(Node $node, array $data, bool $resetToken = false): Node
{
if ($resetToken) {
$data['daemon_token'] = $this->encrypter->encrypt(Str::random(Node::DAEMON_TOKEN_LENGTH));
@ -87,7 +61,7 @@ class NodeUpdateService
// but something went wrong with Wings we just want to store the update and let the user manually
// make changes as needed.
//
// This avoids issues with proxies such as CloudFlare which will see Wings as offline and then
// This avoids issues with proxies such as Cloudflare which will see Wings as offline and then
// inject their own response pages, causing this logic to get fucked up.
//
// @see https://github.com/pterodactyl/panel/issues/2712

View file

@ -13,29 +13,11 @@ use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
class ProcessScheduleService
{
/**
* @var \Illuminate\Contracts\Bus\Dispatcher
*/
private $dispatcher;
/**
* @var \Illuminate\Database\ConnectionInterface
*/
private $connection;
/**
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
*/
private $serverRepository;
/**
* ProcessScheduleService constructor.
*/
public function __construct(ConnectionInterface $connection, DaemonServerRepository $serverRepository, Dispatcher $dispatcher)
public function __construct(private ConnectionInterface $connection, private Dispatcher $dispatcher, private DaemonServerRepository $serverRepository)
{
$this->dispatcher = $dispatcher;
$this->connection = $connection;
$this->serverRepository = $serverRepository;
}
/**
@ -43,7 +25,7 @@ class ProcessScheduleService
*
* @throws \Throwable
*/
public function handle(Schedule $schedule, bool $now = false)
public function handle(Schedule $schedule, bool $now = false): void
{
/** @var \Pterodactyl\Models\Task $task */
$task = $schedule->tasks()->orderBy('sequence_id')->first();

View file

@ -14,45 +14,23 @@ use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
class BuildModificationService
{
/**
* @var \Illuminate\Database\ConnectionInterface
*/
private $connection;
/**
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
*/
private $daemonServerRepository;
/**
* @var \Pterodactyl\Services\Servers\ServerConfigurationStructureService
*/
private $structureService;
/**
* BuildModificationService constructor.
*
* @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $structureService
*/
public function __construct(
ServerConfigurationStructureService $structureService,
ConnectionInterface $connection,
DaemonServerRepository $daemonServerRepository
private ConnectionInterface $connection,
private DaemonServerRepository $daemonServerRepository,
private ServerConfigurationStructureService $structureService
) {
$this->daemonServerRepository = $daemonServerRepository;
$this->connection = $connection;
$this->structureService = $structureService;
}
/**
* Change the build details for a specified server.
*
* @return \Pterodactyl\Models\Server
*
* @throws \Throwable
* @throws \Pterodactyl\Exceptions\DisplayException
*/
public function handle(Server $server, array $data)
public function handle(Server $server, array $data): Server
{
/** @var \Pterodactyl\Models\Server $server */
$server = $this->connection->transaction(function () use ($server, $data) {
@ -61,7 +39,7 @@ class BuildModificationService
if (isset($data['allocation_id']) && $data['allocation_id'] != $server->allocation_id) {
try {
Allocation::query()->where('id', $data['allocation_id'])->where('server_id', $server->id)->firstOrFail();
} catch (ModelNotFoundException $ex) {
} catch (ModelNotFoundException) {
throw new DisplayException('The requested default allocation is not currently assigned to this server.');
}
}
@ -101,7 +79,7 @@ class BuildModificationService
*
* @throws \Pterodactyl\Exceptions\DisplayException
*/
private function processAllocations(Server $server, array &$data)
private function processAllocations(Server $server, array &$data): void
{
if (empty($data['add_allocations']) && empty($data['remove_allocations'])) {
return;

View file

@ -13,23 +13,11 @@ class DetailsModificationService
{
use ReturnsUpdatedModels;
/**
* @var \Illuminate\Database\ConnectionInterface
*/
private $connection;
/**
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
*/
private $serverRepository;
/**
* DetailsModificationService constructor.
*/
public function __construct(ConnectionInterface $connection, DaemonServerRepository $serverRepository)
public function __construct(private ConnectionInterface $connection, private DaemonServerRepository $serverRepository)
{
$this->connection = $connection;
$this->serverRepository = $serverRepository;
}
/**
@ -57,7 +45,7 @@ class DetailsModificationService
$this->serverRepository->setServer($server)->revokeUserJTI($owner);
} catch (DaemonConnectionException $exception) {
// Do nothing. A failure here is not ideal, but it is likely to be caused by Wings
// being offline, or in an entirely broken state. Remeber, these tokens reset every
// being offline, or in an entirely broken state. Remember, these tokens reset every
// few minutes by default, we're just trying to help it along a little quicker.
}
}

View file

@ -7,16 +7,13 @@ use Pterodactyl\Models\EggVariable;
class EnvironmentService
{
/**
* @var array
*/
private $additional = [];
private array $additional = [];
/**
* Dynamically configure additional environment variables to be assigned
* with a specific server.
*/
public function setEnvironmentKey(string $key, callable $closure)
public function setEnvironmentKey(string $key, callable $closure): void
{
$this->additional[$key] = $closure;
}

View file

@ -11,10 +11,8 @@ class GetUserPermissionsService
* Returns the server specific permissions that a user has. This checks
* if they are an admin or a subuser for the server. If no permissions are
* found, an empty array is returned.
*
* @return string[]
*/
public function handle(Server $server, User $user)
public function handle(Server $server, User $user): array
{
if ($user->root_admin || $user->id === $server->owner_id) {
$permissions = ['*'];

View file

@ -8,35 +8,21 @@ use Pterodactyl\Repositories\Wings\DaemonServerRepository;
class ReinstallServerService
{
/**
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
*/
private $daemonServerRepository;
/**
* @var \Illuminate\Database\ConnectionInterface
*/
private $connection;
/**
* ReinstallService constructor.
*/
public function __construct(
ConnectionInterface $connection,
DaemonServerRepository $daemonServerRepository
private ConnectionInterface $connection,
private DaemonServerRepository $daemonServerRepository
) {
$this->daemonServerRepository = $daemonServerRepository;
$this->connection = $connection;
}
/**
* Reinstall a server on the remote daemon.
*
* @return \Pterodactyl\Models\Server
*
* @throws \Throwable
*/
public function handle(Server $server)
public function handle(Server $server): Server
{
return $this->connection->transaction(function () use ($server) {
$server->fill(['status' => Server::STATUS_INSTALLING])->save();

View file

@ -7,14 +7,11 @@ use Pterodactyl\Models\Server;
class ServerConfigurationStructureService
{
private EnvironmentService $environment;
/**
* ServerConfigurationStructureService constructor.
*/
public function __construct(EnvironmentService $environment)
public function __construct(private EnvironmentService $environment)
{
$this->environment = $environment;
}
/**

View file

@ -12,7 +12,6 @@ use Illuminate\Support\Collection;
use Pterodactyl\Models\Allocation;
use Illuminate\Database\ConnectionInterface;
use Pterodactyl\Models\Objects\DeploymentObject;
use Pterodactyl\Repositories\Eloquent\EggRepository;
use Pterodactyl\Repositories\Eloquent\ServerRepository;
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
use Pterodactyl\Services\Deployment\FindViableNodesService;
@ -23,84 +22,18 @@ use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
class ServerCreationService
{
/**
* @var \Pterodactyl\Services\Deployment\AllocationSelectionService
*/
private $allocationSelectionService;
/**
* @var \Pterodactyl\Services\Servers\ServerConfigurationStructureService
*/
private $configurationStructureService;
/**
* @var \Illuminate\Database\ConnectionInterface
*/
private $connection;
/**
* @var \Pterodactyl\Services\Deployment\FindViableNodesService
*/
private $findViableNodesService;
/**
* @var \Pterodactyl\Services\Servers\VariableValidatorService
*/
private $validatorService;
/**
* @var \Pterodactyl\Repositories\Eloquent\EggRepository
*/
private $eggRepository;
/**
* @var \Pterodactyl\Repositories\Eloquent\ServerRepository
*/
private $repository;
/**
* @var \Pterodactyl\Repositories\Eloquent\ServerVariableRepository
*/
private $serverVariableRepository;
/**
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
*/
private $daemonServerRepository;
/**
* @var \Pterodactyl\Services\Servers\ServerDeletionService
*/
private $serverDeletionService;
/**
* CreationService constructor.
*
* @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $configurationStructureService
* @param \Pterodactyl\Services\Servers\ServerDeletionService $serverDeletionService
* @param \Pterodactyl\Services\Servers\VariableValidatorService $validatorService
* ServerCreationService constructor.
*/
public function __construct(
AllocationSelectionService $allocationSelectionService,
ConnectionInterface $connection,
DaemonServerRepository $daemonServerRepository,
EggRepository $eggRepository,
FindViableNodesService $findViableNodesService,
ServerConfigurationStructureService $configurationStructureService,
ServerDeletionService $serverDeletionService,
ServerRepository $repository,
ServerVariableRepository $serverVariableRepository,
VariableValidatorService $validatorService
private AllocationSelectionService $allocationSelectionService,
private ConnectionInterface $connection,
private DaemonServerRepository $daemonServerRepository,
private FindViableNodesService $findViableNodesService,
private ServerRepository $repository,
private ServerDeletionService $serverDeletionService,
private ServerVariableRepository $serverVariableRepository,
private VariableValidatorService $validatorService
) {
$this->allocationSelectionService = $allocationSelectionService;
$this->configurationStructureService = $configurationStructureService;
$this->connection = $connection;
$this->findViableNodesService = $findViableNodesService;
$this->validatorService = $validatorService;
$this->eggRepository = $eggRepository;
$this->repository = $repository;
$this->serverVariableRepository = $serverVariableRepository;
$this->daemonServerRepository = $daemonServerRepository;
$this->serverDeletionService = $serverDeletionService;
}
/**
@ -237,7 +170,7 @@ class ServerCreationService
/**
* Configure the allocations assigned to this server.
*/
private function storeAssignedAllocations(Server $server, array $data)
private function storeAssignedAllocations(Server $server, array $data): void
{
$records = [$data['allocation_id']];
if (isset($data['allocation_additional']) && is_array($data['allocation_additional'])) {
@ -252,7 +185,7 @@ class ServerCreationService
/**
* Process environment variables passed for this server and store them in the database.
*/
private function storeEggVariables(Server $server, Collection $variables)
private function storeEggVariables(Server $server, Collection $variables): void
{
$records = $variables->map(function ($result) use ($server) {
return [

View file

@ -13,47 +13,22 @@ use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
class ServerDeletionService
{
/**
* @var bool
*/
protected $force = false;
protected bool $force = false;
/**
* @var \Illuminate\Database\ConnectionInterface
*/
private $connection;
/**
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
*/
private $daemonServerRepository;
/**
* @var \Pterodactyl\Services\Databases\DatabaseManagementService
*/
private $databaseManagementService;
/**
* DeletionService constructor.
* ServerDeletionService constructor.
*/
public function __construct(
ConnectionInterface $connection,
DaemonServerRepository $daemonServerRepository,
DatabaseManagementService $databaseManagementService
private ConnectionInterface $connection,
private DaemonServerRepository $daemonServerRepository,
private DatabaseManagementService $databaseManagementService
) {
$this->connection = $connection;
$this->daemonServerRepository = $daemonServerRepository;
$this->databaseManagementService = $databaseManagementService;
}
/**
* Set if the server should be forcibly deleted from the panel (ignoring daemon errors) or not.
*
* @param bool $bool
*
* @return $this
*/
public function withForce($bool = true)
public function withForce(bool $bool = true): self
{
$this->force = $bool;
@ -66,7 +41,7 @@ class ServerDeletionService
* @throws \Throwable
* @throws \Pterodactyl\Exceptions\DisplayException
*/
public function handle(Server $server)
public function handle(Server $server): void
{
try {
$this->daemonServerRepository->setServer($server)->delete();

View file

@ -14,25 +14,11 @@ class StartupModificationService
{
use HasUserLevels;
/**
* @var \Illuminate\Database\ConnectionInterface
*/
private $connection;
/**
* @var \Pterodactyl\Services\Servers\VariableValidatorService
*/
private $validatorService;
/**
* StartupModificationService constructor.
*
* @param \Pterodactyl\Services\Servers\VariableValidatorService $validatorService
*/
public function __construct(ConnectionInterface $connection, VariableValidatorService $validatorService)
public function __construct(private ConnectionInterface $connection, private VariableValidatorService $validatorService)
{
$this->connection = $connection;
$this->validatorService = $validatorService;
}
/**
@ -79,7 +65,7 @@ class StartupModificationService
/**
* Update certain administrative settings for a server in the DB.
*/
protected function updateAdministrativeSettings(array $data, Server &$server)
protected function updateAdministrativeSettings(array $data, Server &$server): void
{
$eggId = Arr::get($data, 'egg_id');

View file

@ -4,7 +4,6 @@ namespace Pterodactyl\Services\Servers;
use Webmozart\Assert\Assert;
use Pterodactyl\Models\Server;
use Illuminate\Database\ConnectionInterface;
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
@ -13,42 +12,27 @@ class SuspensionService
public const ACTION_SUSPEND = 'suspend';
public const ACTION_UNSUSPEND = 'unsuspend';
/**
* @var \Illuminate\Database\ConnectionInterface
*/
private $connection;
/**
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
*/
private $daemonServerRepository;
/**
* SuspensionService constructor.
*/
public function __construct(
ConnectionInterface $connection,
DaemonServerRepository $daemonServerRepository
private DaemonServerRepository $daemonServerRepository
) {
$this->connection = $connection;
$this->daemonServerRepository = $daemonServerRepository;
}
/**
* Suspends a server on the system.
*
* @param string $action
*
* @throws \Throwable
*/
public function toggle(Server $server, $action = self::ACTION_SUSPEND)
public function toggle(Server $server, string $action = self::ACTION_SUSPEND): void
{
Assert::oneOf($action, [self::ACTION_SUSPEND, self::ACTION_UNSUSPEND]);
$isSuspending = $action === self::ACTION_SUSPEND;
// Nothing needs to happen if we're suspending the server and it is already
// Nothing needs to happen if we're suspending the server, and it is already
// suspended in the database. Additionally, nothing needs to happen if the server
// is not suspended and we try to un-suspend the instance.
// is not suspended, and we try to un-suspend the instance.
if ($isSuspending === $server->isSuspended()) {
return;
}

View file

@ -4,39 +4,23 @@ namespace Pterodactyl\Services\Servers;
use Pterodactyl\Models\Server;
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
class TransferService
{
/**
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
*/
private $repository;
/**
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
*/
private $daemonServerRepository;
/**
* TransferService constructor.
*/
public function __construct(
DaemonServerRepository $daemonServerRepository,
ServerRepositoryInterface $repository
private DaemonServerRepository $daemonServerRepository
) {
$this->repository = $repository;
$this->daemonServerRepository = $daemonServerRepository;
}
/**
* Requests an archive from the daemon.
*
* @param int|\Pterodactyl\Models\Server $server
*
* @throws \Throwable
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
*/
public function requestArchive(Server $server)
public function requestArchive(Server $server): void
{
$this->daemonServerRepository->setServer($server)->requestArchive();
}

View file

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Services\Servers;
@ -20,17 +13,11 @@ class VariableValidatorService
{
use HasUserLevels;
/**
* @var \Illuminate\Contracts\Validation\Factory
*/
private $validator;
/**
* VariableValidatorService constructor.
*/
public function __construct(ValidationFactory $validator)
public function __construct(private ValidationFactory $validator)
{
$this->validator = $validator;
}
/**
@ -42,7 +29,7 @@ class VariableValidatorService
{
$query = EggVariable::query()->where('egg_id', $egg);
if (!$this->isUserLevel(User::USER_LEVEL_ADMIN)) {
// Don't attempt to validate variables if they aren't user editable
// Don't attempt to validate variables if they aren't user editable,
// and we're not running this at an admin level.
$query = $query->where('user_editable', true)->where('user_viewable', true);
}

View file

@ -15,39 +15,15 @@ use Pterodactyl\Exceptions\Service\Subuser\ServerSubuserExistsException;
class SubuserCreationService
{
/**
* @var \Illuminate\Database\ConnectionInterface
*/
private $connection;
/**
* @var \Pterodactyl\Repositories\Eloquent\SubuserRepository
*/
private $subuserRepository;
/**
* @var \Pterodactyl\Services\Users\UserCreationService
*/
private $userCreationService;
/**
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface
*/
private $userRepository;
/**
* SubuserCreationService constructor.
*/
public function __construct(
ConnectionInterface $connection,
SubuserRepository $subuserRepository,
UserCreationService $userCreationService,
UserRepositoryInterface $userRepository
private ConnectionInterface $connection,
private SubuserRepository $subuserRepository,
private UserCreationService $userCreationService,
private UserRepositoryInterface $userRepository
) {
$this->connection = $connection;
$this->subuserRepository = $subuserRepository;
$this->userRepository = $userRepository;
$this->userCreationService = $userCreationService;
}
/**
@ -74,7 +50,7 @@ class SubuserCreationService
if ($subuserCount !== 0) {
throw new ServerSubuserExistsException(trans('exceptions.subusers.subuser_exists'));
}
} catch (RecordNotFoundException $exception) {
} catch (RecordNotFoundException) {
// Just cap the username generated at 64 characters at most and then append a random string
// to the end to make it "unique"...
$username = substr(preg_replace('/([^\w\.-]+)/', '', strtok($email, '@')), 0, 64) . Str::random(3);

View file

@ -14,53 +14,21 @@ use Pterodactyl\Exceptions\Service\User\TwoFactorAuthenticationTokenInvalid;
class ToggleTwoFactorService
{
/**
* @var \Illuminate\Contracts\Encryption\Encrypter
*/
private $encrypter;
/**
* @var \PragmaRX\Google2FA\Google2FA
*/
private $google2FA;
/**
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface
*/
private $repository;
/**
* @var \Pterodactyl\Repositories\Eloquent\RecoveryTokenRepository
*/
private $recoveryTokenRepository;
/**
* @var \Illuminate\Database\ConnectionInterface
*/
private $connection;
/**
* ToggleTwoFactorService constructor.
*/
public function __construct(
ConnectionInterface $connection,
Encrypter $encrypter,
Google2FA $google2FA,
RecoveryTokenRepository $recoveryTokenRepository,
UserRepositoryInterface $repository
private ConnectionInterface $connection,
private Encrypter $encrypter,
private Google2FA $google2FA,
private RecoveryTokenRepository $recoveryTokenRepository,
private UserRepositoryInterface $repository
) {
$this->encrypter = $encrypter;
$this->google2FA = $google2FA;
$this->repository = $repository;
$this->recoveryTokenRepository = $recoveryTokenRepository;
$this->connection = $connection;
}
/**
* Toggle 2FA on an account only if the token provided is valid.
*
* @return string[]
*
* @throws \Throwable
* @throws \PragmaRX\Google2FA\Exceptions\IncompatibleWithGoogleAuthenticatorException
* @throws \PragmaRX\Google2FA\Exceptions\InvalidCharactersException

View file

@ -13,32 +13,14 @@ class TwoFactorSetupService
{
public const VALID_BASE32_CHARACTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
/**
* @var \Illuminate\Contracts\Config\Repository
*/
private $config;
/**
* @var \Illuminate\Contracts\Encryption\Encrypter
*/
private $encrypter;
/**
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface
*/
private $repository;
/**
* TwoFactorSetupService constructor.
*/
public function __construct(
ConfigRepository $config,
Encrypter $encrypter,
UserRepositoryInterface $repository
private ConfigRepository $config,
private Encrypter $encrypter,
private UserRepositoryInterface $repository
) {
$this->config = $config;
$this->encrypter = $encrypter;
$this->repository = $repository;
}
/**

View file

@ -3,6 +3,7 @@
namespace Pterodactyl\Services\Users;
use Ramsey\Uuid\Uuid;
use Pterodactyl\Models\User;
use Illuminate\Contracts\Hashing\Hasher;
use Illuminate\Database\ConnectionInterface;
use Illuminate\Contracts\Auth\PasswordBroker;
@ -12,49 +13,23 @@ use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
class UserCreationService
{
/**
* @var \Illuminate\Database\ConnectionInterface
*/
private $connection;
/**
* @var \Illuminate\Contracts\Hashing\Hasher
*/
private $hasher;
/**
* @var \Illuminate\Contracts\Auth\PasswordBroker
*/
private $passwordBroker;
/**
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface
*/
private $repository;
/**
* CreationService constructor.
* UserCreationService constructor.
*/
public function __construct(
ConnectionInterface $connection,
Hasher $hasher,
PasswordBroker $passwordBroker,
UserRepositoryInterface $repository
private ConnectionInterface $connection,
private Hasher $hasher,
private PasswordBroker $passwordBroker,
private UserRepositoryInterface $repository
) {
$this->connection = $connection;
$this->hasher = $hasher;
$this->passwordBroker = $passwordBroker;
$this->repository = $repository;
}
/**
* Create a new user on the system.
*
* @return \Pterodactyl\Models\User
*
* @throws \Exception
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
*/
public function handle(array $data)
public function handle(array $data): User
{
if (array_key_exists('password', $data) && !empty($data['password'])) {
$data['password'] = $this->hasher->make($data['password']);

View file

@ -1,13 +1,5 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Services\Users;
use Pterodactyl\Models\User;
@ -19,43 +11,21 @@ use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
class UserDeletionService
{
/**
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface
*/
protected $repository;
/**
* @var \Illuminate\Contracts\Translation\Translator
*/
protected $translator;
/**
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
*/
protected $serverRepository;
/**
* DeletionService constructor.
* UserDeletionService constructor.
*/
public function __construct(
ServerRepositoryInterface $serverRepository,
Translator $translator,
UserRepositoryInterface $repository
protected UserRepositoryInterface $repository,
protected ServerRepositoryInterface $serverRepository,
protected Translator $translator
) {
$this->repository = $repository;
$this->translator = $translator;
$this->serverRepository = $serverRepository;
}
/**
* Delete a user from the panel only if they have no servers attached to their account.
*
* @param int|\Pterodactyl\Models\User $user
*
* @return bool|null
*
* @throws \Pterodactyl\Exceptions\DisplayException
*/
public function handle($user)
public function handle(int|User $user): ?bool
{
if ($user instanceof User) {
$user = $user->id;

View file

@ -11,16 +11,10 @@ class UserUpdateService
use HasUserLevels;
/**
* @var \Illuminate\Contracts\Hashing\Hasher
* UserUpdateService constructor.
*/
private $hasher;
/**
* UpdateService constructor.
*/
public function __construct(Hasher $hasher)
public function __construct(private Hasher $hasher)
{
$this->hasher = $hasher;
}
/**