Files

70 lines
1.7 KiB
PHP
Raw Permalink 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 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
/**
2026-10-11 22:55:07 -04:00
* @property string|null $server_value only set when loaded through Server::variables()
*/
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;
2026-10-05 18:10:18 -04:00
public const string RESOURCE_NAME = 'egg_variable';
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',
2026-10-11 23:29:38 -04:00
'env_variable' => 'string',
2026-10-05 18:10:18 -04:00
'user_viewable' => 'bool',
'user_editable' => 'bool',
'sort_order' => 'integer',
];
}
/**
2026-10-05 18:10:18 -04:00
* @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);
}
/**
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
{
2026-10-11 22:55:07 -04:00
return Attribute::make(get: fn (): bool => in_array('required', explode('|', $this->rules ?? '')));
2026-10-05 18:10:18 -04:00
}
2015-12-08 18:33:33 -05:00
}