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
|
|
|
|
2020-08-22 15:43:28 -07:00
|
|
|
/**
|
2026-10-11 22:55:07 -04:00
|
|
|
* @property string|null $server_value only set when loaded through Server::variables()
|
2020-08-22 15:43:28 -07:00
|
|
|
*/
|
2026-10-05 18:10:18 -04:00
|
|
|
#[Guarded(['id', 'created_at', 'updated_at'])]
|
2020-04-03 23:22:35 -07:00
|
|
|
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';
|
2018-01-25 21:26:06 -06:00
|
|
|
|
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';
|
2017-08-08 23:24:55 -05:00
|
|
|
|
|
|
|
|
protected $attributes = [
|
|
|
|
|
'user_editable' => 0,
|
|
|
|
|
'user_viewable' => 0,
|
|
|
|
|
];
|
2017-05-01 17:01:46 -04:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
/**
|
|
|
|
|
* @return array<string, string>
|
|
|
|
|
*/
|
|
|
|
|
protected function casts(): array
|
2020-08-22 15:43:28 -07:00
|
|
|
{
|
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',
|
|
|
|
|
];
|
2020-08-22 15:43:28 -07:00
|
|
|
}
|
|
|
|
|
|
2025-12-20 15:55:13 -08:00
|
|
|
/**
|
2026-10-05 18:10:18 -04:00
|
|
|
* @return BelongsTo<Egg, $this>
|
2025-12-20 15:55:13 -08:00
|
|
|
*/
|
2026-10-05 18:10:18 -04:00
|
|
|
public function egg(): BelongsTo
|
2017-03-12 19:34:06 -04:00
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
return $this->belongsTo(Egg::class);
|
2017-03-12 19:34:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2026-10-05 18:10:18 -04:00
|
|
|
* @return HasMany<ServerVariable, $this>
|
2017-03-12 19:34:06 -04:00
|
|
|
*/
|
2022-10-14 10:59:20 -06:00
|
|
|
public function serverVariable(): HasMany
|
2017-02-12 15:10:39 -05:00
|
|
|
{
|
2017-02-12 16:03:17 -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
|
|
|
}
|