misc_pterodactyl-panel/app/Services/Eggs/EggCreationService.php

47 lines
1.5 KiB
PHP
Raw Permalink Normal View History

<?php
namespace Pterodactyl\Services\Eggs;
2017-10-03 03:51:13 +00:00
use Ramsey\Uuid\Uuid;
use Pterodactyl\Models\Egg;
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
2017-10-03 03:51:13 +00:00
use Illuminate\Contracts\Config\Repository as ConfigRepository;
use Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException;
2018-05-13 14:50:56 +00:00
// 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 \Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException
*/
public function handle(array $data): Egg
{
$data['config_from'] = array_get($data, 'config_from');
2021-01-23 20:33:34 +00:00
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) {
2017-10-08 20:29:46 +00:00
throw new NoParentConfigurationFoundException(trans('exceptions.nest.egg.must_be_child'));
}
2017-10-03 03:51:13 +00:00
}
return $this->repository->create(array_merge($data, [
'uuid' => Uuid::uuid4()->toString(),
'author' => $this->config->get('pterodactyl.service.author'),
2017-10-03 03:51:13 +00:00
]), true, true);
}
}