ldc-arcadia-api/database/seeders/ApiClientSeeder.php

41 lines
1.3 KiB
PHP
Raw Normal View History

<?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);
}
}