Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Services/Nodes/NodeCreationService.php
10262 views
1
<?php
2
3
namespace Pterodactyl\Services\Nodes;
4
5
use Ramsey\Uuid\Uuid;
6
use Illuminate\Support\Str;
7
use Pterodactyl\Models\Node;
8
use Illuminate\Contracts\Encryption\Encrypter;
9
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
10
11
class NodeCreationService
12
{
13
/**
14
* NodeCreationService constructor.
15
*/
16
public function __construct(protected NodeRepositoryInterface $repository)
17
{
18
}
19
20
/**
21
* Create a new node on the panel.
22
*
23
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
24
*/
25
public function handle(array $data): Node
26
{
27
$data['uuid'] = Uuid::uuid4()->toString();
28
$data['daemon_token'] = app(Encrypter::class)->encrypt(Str::random(Node::DAEMON_TOKEN_LENGTH));
29
$data['daemon_token_id'] = Str::random(Node::DAEMON_TOKEN_ID_LENGTH);
30
31
return $this->repository->create($data, true, true);
32
}
33
}
34
35