forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEggCreationService.php
More file actions
46 lines (40 loc) · 1.49 KB
/
EggCreationService.php
File metadata and controls
46 lines (40 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace Pterodactyl\Services\Eggs;
use Ramsey\Uuid\Uuid;
use Pterodactyl\Models\Egg;
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
use Illuminate\Contracts\Config\Repository as ConfigRepository;
use Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException;
// When a mommy and a daddy pterodactyl really like each other...
class EggCreationService
{
/**
* EggCreationService constructor.
*/
public function __construct(private ConfigRepository $config, private EggRepositoryInterface $repository)
{
}
/**
* Create a new service option and assign it to the given service.
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws NoParentConfigurationFoundException
*/
public function handle(array $data): Egg
{
$data['config_from'] = array_get($data, 'config_from');
if (!is_null($data['config_from'])) {
$results = $this->repository->findCountWhere([
['nest_id', '=', array_get($data, 'nest_id')],
['id', '=', array_get($data, 'config_from')],
]);
if ($results !== 1) {
throw new NoParentConfigurationFoundException(trans('exceptions.nest.egg.must_be_child'));
}
}
return $this->repository->create(array_merge($data, [
'uuid' => Uuid::uuid4()->toString(),
'author' => $this->config->get('pterodactyl.service.author'),
]), true, true);
}
}