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
|
|
|
|
2020-08-22 15:43:28 -07:00
|
|
|
/**
|
2021-01-27 20:52:11 -08: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
|
2021-01-27 20:52:11 -08:00
|
|
|
* @property bool $required
|
2024-10-21 19:18:20 -06:00
|
|
|
* @property Egg $egg
|
|
|
|
|
* @property ServerVariable $serverVariable
|
2020-08-22 15:43:28 -07:00
|
|
|
*
|
|
|
|
|
* 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'])]
|
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;
|
|
|
|
|
|
2018-01-25 21:26:06 -06:00
|
|
|
/**
|
|
|
|
|
* 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';
|
2018-01-25 21:26:06 -06:00
|
|
|
|
2017-08-08 23:24:55 -05:00
|
|
|
/**
|
|
|
|
|
* 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';
|
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',
|
|
|
|
|
'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
|
|
|
* The egg this variable is defined on.
|
|
|
|
|
*
|
|
|
|
|
* @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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return server variables associated with this variable.
|
2025-12-20 15:55:13 -08: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
|
|
|
|
|
{
|
|
|
|
|
return Attribute::make(get: fn (): bool => in_array('required', explode('|', $this->rules)));
|
|
|
|
|
}
|
2015-12-08 18:33:33 -05:00
|
|
|
}
|