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

@ -9,64 +9,45 @@ use Illuminate\Support\Str;
use Webmozart\Assert\Assert;
use InvalidArgumentException;
use Illuminate\Foundation\Application;
use League\Flysystem\AdapterInterface;
use League\Flysystem\AwsS3v3\AwsS3Adapter;
use League\Flysystem\Memory\MemoryAdapter;
use Illuminate\Contracts\Config\Repository;
use League\Flysystem\FilesystemAdapter;
use Pterodactyl\Extensions\Filesystem\S3Filesystem;
use League\Flysystem\InMemory\InMemoryFilesystemAdapter;
use Illuminate\Contracts\Config\Repository as ConfigRepository;
class BackupManager
{
/**
* @var \Illuminate\Foundation\Application
*/
protected $app;
/**
* @var \Illuminate\Contracts\Config\Repository
*/
protected $config;
protected ConfigRepository $config;
/**
* The array of resolved backup drivers.
*
* @var \League\Flysystem\AdapterInterface[]
*/
protected $adapters = [];
protected array $adapters = [];
/**
* The registered custom driver creators.
*
* @var array
*/
protected $customCreators;
protected array $customCreators;
/**
* BackupManager constructor.
*/
public function __construct(Application $app)
public function __construct(protected Application $app)
{
$this->app = $app;
$this->config = $app->make(Repository::class);
$this->config = $app->make(ConfigRepository::class);
}
/**
* Returns a backup adapter instance.
*
* @return \League\Flysystem\AdapterInterface
*/
public function adapter(string $name = null)
public function adapter(string $name = null): FilesystemAdapter
{
return $this->get($name ?: $this->getDefaultAdapter());
}
/**
* Set the given backup adapter instance.
*
* @param \League\Flysystem\AdapterInterface $disk
*
* @return $this
*/
public function set(string $name, $disk)
public function set(string $name, FilesystemAdapter $disk): self
{
$this->adapters[$name] = $disk;
@ -75,25 +56,21 @@ class BackupManager
/**
* Gets a backup adapter.
*
* @return \League\Flysystem\AdapterInterface
*/
protected function get(string $name)
protected function get(string $name): FilesystemAdapter
{
return $this->adapters[$name] = $this->resolve($name);
}
/**
* Resolve the given backup disk.
*
* @return \League\Flysystem\AdapterInterface
*/
protected function resolve(string $name)
protected function resolve(string $name): FilesystemAdapter
{
$config = $this->getConfig($name);
if (empty($config['adapter'])) {
throw new InvalidArgumentException("Backup disk [{$name}] does not have a configured adapter.");
throw new InvalidArgumentException("Backup disk [$name] does not have a configured adapter.");
}
$adapter = $config['adapter'];
@ -106,44 +83,34 @@ class BackupManager
if (method_exists($this, $adapterMethod)) {
$instance = $this->{$adapterMethod}($config);
Assert::isInstanceOf($instance, AdapterInterface::class);
Assert::isInstanceOf($instance, FilesystemAdapter::class);
return $instance;
}
throw new InvalidArgumentException("Adapter [{$adapter}] is not supported.");
throw new InvalidArgumentException("Adapter [$adapter] is not supported.");
}
/**
* Calls a custom creator for a given adapter type.
*
* @return \League\Flysystem\AdapterInterface
*/
protected function callCustomCreator(array $config)
protected function callCustomCreator(array $config): mixed
{
$adapter = $this->customCreators[$config['adapter']]($this->app, $config);
Assert::isInstanceOf($adapter, AdapterInterface::class);
return $adapter;
return $this->customCreators[$config['adapter']]($this->app, $config);
}
/**
* Creates a new wings adapter.
*
* @return \League\Flysystem\AdapterInterface
* Creates a new Wings adapter.
*/
public function createWingsAdapter(array $config)
public function createWingsAdapter(array $config): FilesystemAdapter
{
return new MemoryAdapter(null);
return new InMemoryFilesystemAdapter(null);
}
/**
* Creates a new S3 adapter.
*
* @return \League\Flysystem\AdapterInterface
*/
public function createS3Adapter(array $config)
public function createS3Adapter(array $config): FilesystemAdapter
{
$config['version'] = 'latest';
@ -153,25 +120,21 @@ class BackupManager
$client = new S3Client($config);
return new AwsS3Adapter($client, $config['bucket'], $config['prefix'] ?? '', $config['options'] ?? []);
return new S3Filesystem($client, $config['bucket'], $config['prefix'] ?? '', $config['options'] ?? []);
}
/**
* Returns the configuration associated with a given backup type.
*
* @return array
*/
protected function getConfig(string $name)
protected function getConfig(string $name): array
{
return $this->config->get("backups.disks.{$name}") ?: [];
return $this->config->get("backups.disks.$name") ?: [];
}
/**
* Get the default backup driver name.
*
* @return string
*/
public function getDefaultAdapter()
public function getDefaultAdapter(): string
{
return $this->config->get('backups.default');
}
@ -179,7 +142,7 @@ class BackupManager
/**
* Set the default session driver name.
*/
public function setDefaultAdapter(string $name)
public function setDefaultAdapter(string $name): void
{
$this->config->set('backups.default', $name);
}
@ -188,13 +151,11 @@ class BackupManager
* Unset the given adapter instances.
*
* @param string|string[] $adapter
*
* @return $this
*/
public function forget($adapter)
public function forget(array|string $adapter): self
{
foreach ((array) $adapter as $adapterName) {
unset($this->adapters[$adapter]);
unset($this->adapters[$adapterName]);
}
return $this;
@ -202,10 +163,8 @@ class BackupManager
/**
* Register a custom adapter creator closure.
*
* @return $this
*/
public function extend(string $adapter, Closure $callback)
public function extend(string $adapter, Closure $callback): self
{
$this->customCreators[$adapter] = $callback;

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\Extensions;
@ -20,44 +13,22 @@ class DynamicDatabaseConnection
public const DB_COLLATION = 'utf8_unicode_ci';
public const DB_DRIVER = 'mysql';
/**
* @var \Illuminate\Config\Repository
*/
protected $config;
/**
* @var \Illuminate\Contracts\Encryption\Encrypter
*/
protected $encrypter;
/**
* @var \Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface
*/
protected $repository;
/**
* DynamicDatabaseConnection constructor.
*/
public function __construct(
ConfigRepository $config,
DatabaseHostRepositoryInterface $repository,
Encrypter $encrypter
protected ConfigRepository $config,
protected Encrypter $encrypter,
protected DatabaseHostRepositoryInterface $repository
) {
$this->config = $config;
$this->encrypter = $encrypter;
$this->repository = $repository;
}
/**
* Adds a dynamic database connection entry to the runtime config.
*
* @param string $connection
* @param \Pterodactyl\Models\DatabaseHost|int $host
* @param string $database
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function set($connection, $host, $database = 'mysql')
public function set(string $connection, DatabaseHost|int $host, string $database = 'mysql'): void
{
if (!$host instanceof DatabaseHost) {
$host = $this->repository->find($host);

View file

@ -6,10 +6,7 @@ use Illuminate\Support\Facades\Facade;
class Theme extends Facade
{
/**
* @return string
*/
protected static function getFacadeAccessor()
protected static function getFacadeAccessor(): string
{
return 'extensions.themes';
}

View file

@ -0,0 +1,35 @@
<?php
namespace Pterodactyl\Extensions\Filesystem;
use Aws\S3\S3ClientInterface;
use League\Flysystem\AwsS3V3\AwsS3V3Adapter;
class S3Filesystem extends AwsS3V3Adapter
{
public function __construct(
private S3ClientInterface $client,
private string $bucket,
string $prefix = '',
array $options = [],
) {
parent::__construct(
$client,
$bucket,
$prefix,
null,
null,
$options,
);
}
public function getClient(): S3ClientInterface
{
return $this->client;
}
public function getBucket(): string
{
return $this->bucket;
}
}

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\Extensions;
@ -17,7 +10,7 @@ class Hashids extends VendorHashids implements HashidsInterface
/**
* {@inheritdoc}
*/
public function decodeFirst($encoded, $default = null)
public function decodeFirst(string $encoded, string $default = null): mixed
{
$result = $this->decode($encoded);
if (!is_array($result)) {

View file

@ -8,10 +8,8 @@ class Builder extends EloquentBuilder
{
/**
* Do nothing.
*
* @return $this
*/
public function search()
public function search(): self
{
return $this;
}

View file

@ -2,6 +2,7 @@
namespace Pterodactyl\Extensions\Spatie\Fractalistic;
use League\Fractal\Scope;
use League\Fractal\TransformerAbstract;
use Spatie\Fractal\Fractal as SpatieFractal;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
@ -13,12 +14,10 @@ class Fractal extends SpatieFractal
/**
* Create fractal data.
*
* @return \League\Fractal\Scope
*
* @throws \Spatie\Fractalistic\Exceptions\InvalidTransformation
* @throws \Spatie\Fractalistic\Exceptions\NoTransformerSpecified
*/
public function createData()
public function createData(): Scope
{
// Set the serializer by default.
if (is_null($this->serializer)) {

View file

@ -4,17 +4,17 @@ namespace Pterodactyl\Extensions\Themes;
class Theme
{
public function js($path)
public function js($path): string
{
return sprintf('<script src="%s"></script>' . PHP_EOL, $this->getUrl($path));
}
public function css($path)
public function css($path): string
{
return sprintf('<link media="all" type="text/css" rel="stylesheet" href="%s"/>' . PHP_EOL, $this->getUrl($path));
}
protected function getUrl($path)
protected function getUrl($path): string
{
return '/themes/pterodactyl/' . ltrim($path, '/');
}