Files
pterodactyl-panel/app/Models/EggVariable.php
T

98 lines
2.5 KiB
PHP
Raw Normal View History

2015-12-08 18:33:33 -05:00
<?php
2016-12-07 22:46:38 +00:00
2026-10-05 18:10:18 -04:00
declare(strict_types=1);
2015-12-08 18:33:33 -05:00
namespace Pterodactyl\Models;
2026-10-05 18:10:18 -04:00
use Carbon\CarbonImmutable;
use Database\Factories\EggVariableFactory;
use Illuminate\Database\Eloquent\Attributes\Guarded;
use Illuminate\Database\Eloquent\Casts\Attribute;
2024-10-21 19:18:20 -06:00
use Illuminate\Database\Eloquent\Factories\HasFactory;
2026-10-05 18:10:18 -04:00
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
2022-10-14 10:59:20 -06:00
/**
* @property int $id
* @property int $egg_id
* @property string $name
* @property string $description
* @property string $env_variable
* @property string $default_value
* @property bool $user_viewable
* @property bool $user_editable
* @property string $rules
2026-10-05 18:10:18 -04:00
* @property CarbonImmutable $created_at
* @property CarbonImmutable $updated_at
* @property bool $required
2024-10-21 19:18:20 -06:00
* @property Egg $egg
* @property ServerVariable $serverVariable
*
* The "server_value" variable is only present on the object if you've loaded this model
* using the server relationship.
* @property string|null $server_value
*/
2026-10-05 18:10:18 -04:00
#[Guarded(['id', 'created_at', 'updated_at'])]
class EggVariable extends Model
2015-12-08 18:33:33 -05:00
{
2026-10-05 18:10:18 -04:00
/** @use HasFactory<EggVariableFactory> */
2024-10-21 19:18:20 -06:00
use HasFactory;
/**
* The resource name for this model when it is transformed into an
* API representation using fractal.
*/
2026-10-05 18:10:18 -04:00
public const string RESOURCE_NAME = 'egg_variable';
/**
* Reserved environment variable names.
*/
2026-10-05 18:10:18 -04:00
public const string RESERVED_ENV_NAMES = 'SERVER_MEMORY,SERVER_IP,SERVER_PORT,ENV,HOME,USER,STARTUP,SERVER_UUID,UUID';
protected $attributes = [
'user_editable' => 0,
'user_viewable' => 0,
];
2026-10-05 18:10:18 -04:00
/**
* @return array<string, string>
*/
protected function casts(): array
{
2026-10-05 18:10:18 -04:00
return [
'egg_id' => 'integer',
'user_viewable' => 'bool',
'user_editable' => 'bool',
'sort_order' => 'integer',
];
}
/**
2026-10-05 18:10:18 -04:00
* The egg this variable is defined on.
*
* @return BelongsTo<Egg, $this>
*/
2026-10-05 18:10:18 -04:00
public function egg(): BelongsTo
{
2026-10-05 18:10:18 -04:00
return $this->belongsTo(Egg::class);
}
/**
* Return server variables associated with this variable.
*
2026-10-05 18:10:18 -04:00
* @return HasMany<ServerVariable, $this>
*/
2022-10-14 10:59:20 -06:00
public function serverVariable(): HasMany
2017-02-12 15:10:39 -05:00
{
return $this->hasMany(ServerVariable::class, 'variable_id');
2017-02-12 15:10:39 -05:00
}
2026-10-05 18:10:18 -04:00
/**
* @return Attribute<bool, never>
*/
protected function required(): Attribute
{
return Attribute::make(get: fn (): bool => in_array('required', explode('|', $this->rules)));
}
2015-12-08 18:33:33 -05:00
}