2017-08-16 03:21:47 +00:00
|
|
|
<?php
|
|
|
|
|
2017-10-07 04:57:53 +00:00
|
|
|
namespace Pterodactyl\Services\Nests;
|
2017-08-16 03:21:47 +00:00
|
|
|
|
2017-10-03 03:51:13 +00:00
|
|
|
use Ramsey\Uuid\Uuid;
|
2017-10-07 04:57:53 +00:00
|
|
|
use Pterodactyl\Models\Nest;
|
|
|
|
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
|
2017-08-16 03:21:47 +00:00
|
|
|
use Illuminate\Contracts\Config\Repository as ConfigRepository;
|
|
|
|
|
2017-10-07 04:57:53 +00:00
|
|
|
class NestCreationService
|
2017-08-16 03:21:47 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \Illuminate\Contracts\Config\Repository
|
|
|
|
*/
|
2017-11-04 18:01:54 +00:00
|
|
|
private $config;
|
2017-08-16 03:21:47 +00:00
|
|
|
|
|
|
|
/**
|
2017-10-07 04:57:53 +00:00
|
|
|
* @var \Pterodactyl\Contracts\Repository\NestRepositoryInterface
|
2017-08-16 03:21:47 +00:00
|
|
|
*/
|
2017-11-04 18:01:54 +00:00
|
|
|
private $repository;
|
2017-08-16 03:21:47 +00:00
|
|
|
|
|
|
|
/**
|
2017-10-07 04:57:53 +00:00
|
|
|
* NestCreationService constructor.
|
2017-08-16 03:21:47 +00:00
|
|
|
*
|
2019-09-06 04:32:57 +00:00
|
|
|
* @param \Illuminate\Contracts\Config\Repository $config
|
2017-10-07 04:57:53 +00:00
|
|
|
* @param \Pterodactyl\Contracts\Repository\NestRepositoryInterface $repository
|
2017-08-16 03:21:47 +00:00
|
|
|
*/
|
2017-10-08 04:29:08 +00:00
|
|
|
public function __construct(ConfigRepository $config, NestRepositoryInterface $repository)
|
|
|
|
{
|
2017-08-16 03:21:47 +00:00
|
|
|
$this->config = $config;
|
|
|
|
$this->repository = $repository;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-07 04:57:53 +00:00
|
|
|
* Create a new nest on the system.
|
2017-08-16 03:21:47 +00:00
|
|
|
*
|
2019-09-06 04:32:57 +00:00
|
|
|
* @param array $data
|
2017-11-04 18:01:54 +00:00
|
|
|
* @param string|null $author
|
2017-10-07 04:57:53 +00:00
|
|
|
* @return \Pterodactyl\Models\Nest
|
2017-08-16 03:21:47 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
*/
|
2017-11-04 18:01:54 +00:00
|
|
|
public function handle(array $data, string $author = null): Nest
|
2017-08-16 03:21:47 +00:00
|
|
|
{
|
2017-10-03 03:51:13 +00:00
|
|
|
return $this->repository->create([
|
|
|
|
'uuid' => Uuid::uuid4()->toString(),
|
2017-11-04 18:01:54 +00:00
|
|
|
'author' => $author ?? $this->config->get('pterodactyl.service.author'),
|
2017-08-16 03:21:47 +00:00
|
|
|
'name' => array_get($data, 'name'),
|
|
|
|
'description' => array_get($data, 'description'),
|
2017-10-03 03:51:13 +00:00
|
|
|
], true, true);
|
2017-08-16 03:21:47 +00:00
|
|
|
}
|
|
|
|
}
|