Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Models/EggVariable.php
7432 views
1
<?php
2
3
namespace Pterodactyl\Models;
4
5
use Illuminate\Database\Eloquent\Relations\HasOne;
6
use Illuminate\Database\Eloquent\Relations\HasMany;
7
use Illuminate\Database\Eloquent\Factories\HasFactory;
8
9
/**
10
* @property int $id
11
* @property int $egg_id
12
* @property string $name
13
* @property string $description
14
* @property string $env_variable
15
* @property string $default_value
16
* @property bool $user_viewable
17
* @property bool $user_editable
18
* @property string $rules
19
* @property \Carbon\CarbonImmutable $created_at
20
* @property \Carbon\CarbonImmutable $updated_at
21
* @property bool $required
22
* @property Egg $egg
23
* @property ServerVariable $serverVariable
24
*
25
* The "server_value" variable is only present on the object if you've loaded this model
26
* using the server relationship.
27
* @property string|null $server_value
28
*/
29
class EggVariable extends Model
30
{
31
/** @use HasFactory<\Database\Factories\EggVariableFactory> */
32
use HasFactory;
33
34
/**
35
* The resource name for this model when it is transformed into an
36
* API representation using fractal.
37
*/
38
public const RESOURCE_NAME = 'egg_variable';
39
40
/**
41
* Reserved environment variable names.
42
*/
43
public const RESERVED_ENV_NAMES = 'SERVER_MEMORY,SERVER_IP,SERVER_PORT,ENV,HOME,USER,STARTUP,SERVER_UUID,UUID';
44
45
protected bool $immutableDates = true;
46
47
/**
48
* The table associated with the model.
49
*/
50
protected $table = 'egg_variables';
51
52
/**
53
* Fields that are not mass assignable.
54
*/
55
protected $guarded = ['id', 'created_at', 'updated_at'];
56
57
/**
58
* Cast values to correct type.
59
*/
60
protected $casts = [
61
'egg_id' => 'integer',
62
'user_viewable' => 'bool',
63
'user_editable' => 'bool',
64
];
65
66
public static array $validationRules = [
67
'egg_id' => 'exists:eggs,id',
68
'name' => 'required|string|between:1,191',
69
'description' => 'string',
70
'env_variable' => 'required|regex:/^[\w]{1,191}$/|notIn:' . self::RESERVED_ENV_NAMES,
71
'default_value' => 'string',
72
'user_viewable' => 'boolean',
73
'user_editable' => 'boolean',
74
'rules' => 'required|string',
75
];
76
77
protected $attributes = [
78
'user_editable' => 0,
79
'user_viewable' => 0,
80
];
81
82
public function getRequiredAttribute(): bool
83
{
84
return in_array('required', explode('|', $this->rules));
85
}
86
87
public function egg(): HasOne
88
{
89
return $this->hasOne(Egg::class);
90
}
91
92
/**
93
* Return server variables associated with this variable.
94
*/
95
public function serverVariable(): HasMany
96
{
97
return $this->hasMany(ServerVariable::class, 'variable_id');
98
}
99
}
100
101