Files
pterodactyl-panel/database/Factories/ServerFactory.php
T

83 lines
2.3 KiB
PHP
Raw Normal View History

2021-01-23 12:09:16 -08:00
<?php
2026-10-05 18:10:18 -04:00
declare(strict_types=1);
2021-01-23 12:09:16 -08:00
namespace Database\Factories;
2026-10-05 18:10:18 -04:00
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Date;
2021-01-23 12:09:16 -08:00
use Illuminate\Support\Str;
2026-10-05 18:10:18 -04:00
use Pterodactyl\Models\Allocation;
use Pterodactyl\Models\Egg;
use Pterodactyl\Models\EggVariable;
use Pterodactyl\Models\Node;
2021-01-23 12:09:16 -08:00
use Pterodactyl\Models\Server;
2026-10-05 18:10:18 -04:00
use Pterodactyl\Models\User;
use Ramsey\Uuid\Uuid;
2021-01-23 12:09:16 -08:00
2026-10-05 18:10:18 -04:00
/**
* @extends Factory<Server>
*/
2021-01-23 12:09:16 -08:00
class ServerFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Server::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'uuid' => Uuid::uuid4()->toString(),
'uuidShort' => Str::lower(Str::random(8)),
2026-10-05 18:10:18 -04:00
'name' => fake()->firstName(),
'description' => implode(' ', fake()->sentences()),
2021-01-23 12:09:16 -08:00
'skip_scripts' => 0,
2021-01-30 19:12:22 -08:00
'status' => null,
2021-01-23 12:09:16 -08:00
'memory' => 512,
'swap' => 0,
'disk' => 512,
'io' => 500,
'cpu' => 0,
'threads' => null,
'oom_disabled' => 0,
2022-05-29 17:07:34 -04:00
'startup' => '/bin/bash echo "hello world"',
'image' => 'foo/bar:latest',
'allocation_limit' => null,
'database_limit' => null,
2022-05-29 17:07:34 -04:00
'backup_limit' => 0,
2026-10-05 18:10:18 -04:00
'created_at' => Date::now(),
'updated_at' => Date::now(),
2021-01-23 12:09:16 -08:00
];
}
2026-10-05 18:10:18 -04:00
public function withRelationships(): self
{
return $this->state(function (): array {
$node = Node::factory()->withLocation()->create();
$allocation = Allocation::factory()->for($node)->create();
$egg = Egg::factory()->create();
EggVariable::factory()->create(['egg_id' => $egg->id, 'user_viewable' => 1, 'user_editable' => 1]);
return [
'owner_id' => User::factory()->create()->id,
'node_id' => $node->id,
'allocation_id' => $allocation->id,
'egg_id' => $egg->id,
'allocation_limit' => 5,
'database_limit' => 5,
];
})->afterCreating(function (Server $server): void {
$server->allocation()->update(['server_id' => $server->id]);
});
}
2021-01-23 12:09:16 -08:00
}