Files

34 lines
897 B
PHP
Raw Permalink Normal View History

<?php
namespace Pterodactyl\Services\Nodes;
2020-04-16 20:47:53 -04:00
use Ramsey\Uuid\Uuid;
use Illuminate\Support\Str;
use Pterodactyl\Models\Node;
2020-06-24 21:54:56 -07:00
use Illuminate\Contracts\Encryption\Encrypter;
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
class NodeCreationService
{
/**
2022-10-14 10:59:20 -06:00
* NodeCreationService constructor.
*/
public function __construct(protected NodeRepositoryInterface $repository)
{
}
/**
* Create a new node on the panel.
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
*/
2022-10-14 10:59:20 -06:00
public function handle(array $data): Node
{
2020-04-16 20:47:53 -04:00
$data['uuid'] = Uuid::uuid4()->toString();
$data['daemon_token'] = app(Encrypter::class)->encrypt(Str::random(Node::DAEMON_TOKEN_LENGTH));
$data['daemon_token_id'] = Str::random(Node::DAEMON_TOKEN_ID_LENGTH);
return $this->repository->create($data, true, true);
}
}