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

48 lines
1.3 KiB
PHP
Raw Permalink Normal View History

<?php
namespace Pterodactyl\Services\Eggs;
2017-10-02 22:51:13 -05:00
use Ramsey\Uuid\Uuid;
use Pterodactyl\Models\Egg;
2017-10-02 22:51:13 -05:00
use Illuminate\Contracts\Config\Repository as ConfigRepository;
use Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException;
2018-05-13 10:50:56 -04:00
// When a mommy and a daddy pterodactyl really like each other...
class EggCreationService
{
/**
* EggCreationService constructor.
*/
2022-10-23 17:27:18 -04:00
public function __construct(private ConfigRepository $config)
{
}
/**
* Create a new service option and assign it to the given service.
*
2022-10-23 17:27:18 -04:00
* @throws NoParentConfigurationFoundException
*/
public function handle(array $data): Egg
{
$data['config_from'] = array_get($data, 'config_from');
2021-01-23 12:33:34 -08:00
if (!is_null($data['config_from'])) {
2022-10-23 17:27:18 -04:00
$results = Egg::query()
->where('nest_id', array_get($data, 'nest_id'))
->where('id', array_get($data, 'config_from'))
->count();
if ($results !== 1) {
2017-10-08 15:29:46 -05:00
throw new NoParentConfigurationFoundException(trans('exceptions.nest.egg.must_be_child'));
}
2017-10-02 22:51:13 -05:00
}
2022-10-23 17:27:18 -04:00
/** @var Egg $egg */
$egg = Egg::query()->create(array_merge($data, [
2017-10-02 22:51:13 -05:00
'uuid' => Uuid::uuid4()->toString(),
'author' => $this->config->get('pterodactyl.service.author'),
2022-10-23 17:27:18 -04:00
]));
return $egg;
}
}