Path: blob/1.0-develop/app/Repositories/Eloquent/EggRepository.php
7460 views
<?php12namespace Pterodactyl\Repositories\Eloquent;34use Pterodactyl\Models\Egg;5use Webmozart\Assert\Assert;6use Illuminate\Database\Eloquent\Collection;7use Illuminate\Database\Eloquent\ModelNotFoundException;8use Pterodactyl\Contracts\Repository\EggRepositoryInterface;9use Pterodactyl\Exceptions\Repository\RecordNotFoundException;1011class EggRepository extends EloquentRepository implements EggRepositoryInterface12{13/**14* Return the model backing this repository.15*/16public function model(): string17{18return Egg::class;19}2021/**22* Return an egg with the variables relation attached.23*24* @throws RecordNotFoundException25*/26public function getWithVariables(int $id): Egg27{28try {29return $this->getBuilder()->with('variables')->findOrFail($id, $this->getColumns());30} catch (ModelNotFoundException) {31throw new RecordNotFoundException();32}33}3435/**36* Return all eggs and their relations to be used in the daemon API.37*/38public function getAllWithCopyAttributes(): Collection39{40return $this->getBuilder()->with('scriptFrom', 'configFrom')->get($this->getColumns());41}4243/**44* Return an egg with the scriptFrom and configFrom relations loaded onto the model.45*46* @param int|string $value47*48* @throws RecordNotFoundException49*/50public function getWithCopyAttributes($value, string $column = 'id'): Egg51{52Assert::true(is_digit($value) || is_string($value), 'First argument passed to getWithCopyAttributes must be an integer or string, received %s.');5354try {55return $this->getBuilder()->with('scriptFrom', 'configFrom')->where($column, '=', $value)->firstOrFail($this->getColumns());56} catch (ModelNotFoundException) {57throw new RecordNotFoundException();58}59}6061/**62* Return all the data needed to export a service.63*64* @throws RecordNotFoundException65*/66public function getWithExportAttributes(int $id): Egg67{68try {69return $this->getBuilder()->with('scriptFrom', 'configFrom', 'variables')->findOrFail($id, $this->getColumns());70} catch (ModelNotFoundException) {71throw new RecordNotFoundException();72}73}7475/**76* Confirm a copy script belongs to the same nest as the item trying to use it.77*/78public function isCopyableScript(int $copyFromId, int $service): bool79{80return $this->getBuilder()->whereNull('copy_script_from')81->where('id', '=', $copyFromId)82->where('nest_id', '=', $service)83->exists();84}85}868788