mirror of
https://github.com/pterodactyl/panel.git
synced 2026-12-02 12:25:44 -05:00
Start 2.0 development
Co-authored-by: Anthony <anthony@infraly.co> Co-authored-by: Sky Mulley <daniel.mulley@outlook.com>
This commit is contained in:
co-authored by
Anthony
Sky Mulley
parent
98079a0166
commit
6c0413e39b
@@ -1,17 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pterodactyl\Extensions;
|
||||
|
||||
use Pterodactyl\Models\DatabaseHost;
|
||||
use Illuminate\Contracts\Encryption\Encrypter;
|
||||
use Illuminate\Config\Repository as ConfigRepository;
|
||||
use Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface;
|
||||
use Illuminate\Contracts\Encryption\Encrypter;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Pterodactyl\Models\DatabaseHost;
|
||||
|
||||
class DynamicDatabaseConnection
|
||||
{
|
||||
public const DB_CHARSET = 'utf8';
|
||||
public const DB_COLLATION = 'utf8_unicode_ci';
|
||||
public const DB_DRIVER = 'mysql';
|
||||
public const string DB_CHARSET = 'utf8';
|
||||
|
||||
public const string DB_COLLATION = 'utf8_unicode_ci';
|
||||
|
||||
public const string DB_DRIVER = 'mysql';
|
||||
|
||||
/**
|
||||
* DynamicDatabaseConnection constructor.
|
||||
@@ -19,22 +23,20 @@ class DynamicDatabaseConnection
|
||||
public function __construct(
|
||||
protected ConfigRepository $config,
|
||||
protected Encrypter $encrypter,
|
||||
protected DatabaseHostRepositoryInterface $repository,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Adds a dynamic database connection entry to the runtime config.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function set(string $connection, DatabaseHost|int $host, string $database = 'mysql'): void
|
||||
{
|
||||
if (!$host instanceof DatabaseHost) {
|
||||
$host = $this->repository->find($host);
|
||||
if (! $host instanceof DatabaseHost) {
|
||||
$host = DatabaseHost::query()->findOrFail($host);
|
||||
}
|
||||
|
||||
$this->config->set('database.connections.' . $connection, [
|
||||
$this->config->set('database.connections.'.$connection, [
|
||||
'driver' => self::DB_DRIVER,
|
||||
'host' => $host->host,
|
||||
'port' => $host->port,
|
||||
|
||||
Reference in New Issue
Block a user