Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Services/Eggs/Sharing/EggExporterService.php
10311 views
1
<?php
2
3
namespace Pterodactyl\Services\Eggs\Sharing;
4
5
use Carbon\Carbon;
6
use Pterodactyl\Models\Egg;
7
use Illuminate\Support\Collection;
8
use Pterodactyl\Models\EggVariable;
9
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
10
11
class EggExporterService
12
{
13
/**
14
* EggExporterService constructor.
15
*/
16
public function __construct(protected EggRepositoryInterface $repository)
17
{
18
}
19
20
/**
21
* Return a JSON representation of an egg and its variables.
22
*
23
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
24
*/
25
public function handle(int $egg): string
26
{
27
$egg = $this->repository->getWithExportAttributes($egg);
28
29
$struct = [
30
'_comment' => 'DO NOT EDIT: FILE GENERATED AUTOMATICALLY BY PTERODACTYL PANEL - PTERODACTYL.IO',
31
'meta' => [
32
'version' => Egg::EXPORT_VERSION,
33
'update_url' => $egg->update_url,
34
],
35
'exported_at' => Carbon::now()->toAtomString(),
36
'name' => $egg->name,
37
'author' => $egg->author,
38
'description' => $egg->description,
39
'features' => $egg->features,
40
'docker_images' => $egg->docker_images,
41
'file_denylist' => Collection::make($egg->inherit_file_denylist)->filter(function ($value) {
42
return !empty($value);
43
}),
44
'startup' => $egg->startup,
45
'config' => [
46
'files' => $egg->inherit_config_files,
47
'startup' => $egg->inherit_config_startup,
48
'logs' => $egg->inherit_config_logs,
49
'stop' => $egg->inherit_config_stop,
50
],
51
'scripts' => [
52
'installation' => [
53
'script' => $egg->copy_script_install,
54
'container' => $egg->copy_script_container,
55
'entrypoint' => $egg->copy_script_entry,
56
],
57
],
58
'variables' => $egg->variables->transform(function (EggVariable $item) {
59
return Collection::make($item->toArray())
60
->except(['id', 'egg_id', 'created_at', 'updated_at'])
61
->merge(['field_type' => 'text'])
62
->toArray();
63
}),
64
];
65
66
return json_encode($struct, JSON_PRETTY_PRINT);
67
}
68
}
69
70