ldc-arcadia-api/database/seeders/ApiClientSeeder.php
Jérémy Munsch 1842223ddc
refactor(database): improve replicated factories, seeders, and config injection
- AbstractTableFactory delegates connection resolution without hardcoded config keys
- Enforce mandatory connection parameter on Migrator without Infra dependencies
- Inject ArcadiaStorageConfig, AppConfig, and HmacAuthConfig into services, seeders, and health checkers
- Enhance factories and seeders with helper methods (truncate, count, query, new)
- Clean up covers annotations on database seeders integration tests
2026-08-26 17:29:13 +02:00

40 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace Database\Seeders;
use Application\Security\Config\HmacAuthConfig;
use Illuminate\Database\Seeder;
use Illuminate\Support\Str;
use Infra\Database\Models\ApiClient;
final class ApiClientSeeder extends Seeder
{
public function run(?HmacAuthConfig $hmacAuthConfig = null): void
{
$hmacAuthConfig ??= resolve(HmacAuthConfig::class);
$devClient = $hmacAuthConfig->devClient;
if ($devClient === null) {
return;
}
$now = now();
ApiClient::query()->updateOrCreate(
['identifier' => $devClient->identifier->value],
[
'id' => $devClient->id->value,
'name' => $devClient->name->value,
'slug' => Str::slug($devClient->name->value),
'secret' => $devClient->secret->value,
'is_active' => true,
'updated_at' => $now,
]
);
$this->command?->info('API client seeded successfully.');
$this->command?->info('Client ID: ' . $devClient->id->value);
$this->command?->info('Client Identifier: ' . $devClient->identifier->value);
$this->command?->info('Client Secret: ' . $devClient->secret->value);
}
}