Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Services/Eggs/EggCreationService.php
10297 views
1
<?php
2
3
namespace Pterodactyl\Services\Eggs;
4
5
use Ramsey\Uuid\Uuid;
6
use Pterodactyl\Models\Egg;
7
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
8
use Illuminate\Contracts\Config\Repository as ConfigRepository;
9
use Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException;
10
11
// When a mommy and a daddy pterodactyl really like each other...
12
class EggCreationService
13
{
14
/**
15
* EggCreationService constructor.
16
*/
17
public function __construct(private ConfigRepository $config, private EggRepositoryInterface $repository)
18
{
19
}
20
21
/**
22
* Create a new service option and assign it to the given service.
23
*
24
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
25
* @throws NoParentConfigurationFoundException
26
*/
27
public function handle(array $data): Egg
28
{
29
$data['config_from'] = array_get($data, 'config_from');
30
if (!is_null($data['config_from'])) {
31
$results = $this->repository->findCountWhere([
32
['nest_id', '=', array_get($data, 'nest_id')],
33
['id', '=', array_get($data, 'config_from')],
34
]);
35
36
if ($results !== 1) {
37
throw new NoParentConfigurationFoundException(trans('exceptions.nest.egg.must_be_child'));
38
}
39
}
40
41
return $this->repository->create(array_merge($data, [
42
'uuid' => Uuid::uuid4()->toString(),
43
'author' => $this->config->get('pterodactyl.service.author'),
44
]), true, true);
45
}
46
}
47
48