Path: blob/1.0-develop/app/Services/Databases/Hosts/HostCreationService.php
10263 views
<?php12namespace Pterodactyl\Services\Databases\Hosts;34use Pterodactyl\Models\DatabaseHost;5use Illuminate\Database\DatabaseManager;6use Illuminate\Database\ConnectionInterface;7use Illuminate\Contracts\Encryption\Encrypter;8use Pterodactyl\Extensions\DynamicDatabaseConnection;9use Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface;1011class HostCreationService12{13/**14* HostCreationService constructor.15*/16public function __construct(17private ConnectionInterface $connection,18private DatabaseManager $databaseManager,19private DynamicDatabaseConnection $dynamic,20private Encrypter $encrypter,21private DatabaseHostRepositoryInterface $repository,22) {23}2425/**26* Create a new database host on the Panel.27*28* @throws \Throwable29*/30public function handle(array $data): DatabaseHost31{32return $this->connection->transaction(function () use ($data) {33$host = $this->repository->create([34'password' => $this->encrypter->encrypt(array_get($data, 'password')),35'name' => array_get($data, 'name'),36'host' => array_get($data, 'host'),37'port' => array_get($data, 'port'),38'username' => array_get($data, 'username'),39'max_databases' => null,40'node_id' => array_get($data, 'node_id'),41]);4243// Confirm access using the provided credentials before saving data.44$this->dynamic->set('dynamic', $host);45$this->databaseManager->connection('dynamic')->select('SELECT 1 FROM dual');4647return $host;48});49}50}515253