Path: blob/1.0-develop/app/Services/Eggs/EggCreationService.php
10297 views
<?php12namespace Pterodactyl\Services\Eggs;34use Ramsey\Uuid\Uuid;5use Pterodactyl\Models\Egg;6use Pterodactyl\Contracts\Repository\EggRepositoryInterface;7use Illuminate\Contracts\Config\Repository as ConfigRepository;8use Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException;910// When a mommy and a daddy pterodactyl really like each other...11class EggCreationService12{13/**14* EggCreationService constructor.15*/16public function __construct(private ConfigRepository $config, private EggRepositoryInterface $repository)17{18}1920/**21* Create a new service option and assign it to the given service.22*23* @throws \Pterodactyl\Exceptions\Model\DataValidationException24* @throws NoParentConfigurationFoundException25*/26public function handle(array $data): Egg27{28$data['config_from'] = array_get($data, 'config_from');29if (!is_null($data['config_from'])) {30$results = $this->repository->findCountWhere([31['nest_id', '=', array_get($data, 'nest_id')],32['id', '=', array_get($data, 'config_from')],33]);3435if ($results !== 1) {36throw new NoParentConfigurationFoundException(trans('exceptions.nest.egg.must_be_child'));37}38}3940return $this->repository->create(array_merge($data, [41'uuid' => Uuid::uuid4()->toString(),42'author' => $this->config->get('pterodactyl.service.author'),43]), true, true);44}45}464748