-
Notifications
You must be signed in to change notification settings - Fork 0
/
Seeder.php
40 lines (33 loc) · 1.01 KB
/
Seeder.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php declare(strict_types = 1);
namespace LastDragon_ru\LaraASP\Migrator\Seeders;
use Illuminate\Database\Connection;
use Illuminate\Database\Seeder as IlluminateSeeder;
use LastDragon_ru\LaraASP\Migrator\Exceptions\DatabaseSeeded;
use Override;
/**
* Smart Seeder. Unlike standard seeder, it checks and stops seeding if the
* database is already seeded.
*/
abstract class Seeder extends IlluminateSeeder {
public function __construct(
protected readonly SeederService $service,
) {
// empty
}
/**
* @param array<array-key, mixed> $parameters
*/
#[Override]
public function __invoke(array $parameters = []): mixed {
if ($this->isSeeded()) {
throw new DatabaseSeeded($this::class);
}
return parent::__invoke($parameters);
}
protected function isSeeded(): bool {
return $this->service->isSeeded($this->getConnection());
}
protected function getConnection(): Connection|string|null {
return null;
}
}