66use Codemonster \Database \Migrations \MigrationPathResolver ;
77use Codemonster \Database \Migrations \MigrationRepository ;
88use Codemonster \Database \Migrations \Migrator ;
9+ use Codemonster \Database \Seeders \SeedPathResolver ;
10+ use Codemonster \Database \Seeders \SeederRunner ;
911use Codemonster \Database \CLI \Commands \MigrateCommand ;
1012use Codemonster \Database \CLI \Commands \RollbackCommand ;
1113use Codemonster \Database \CLI \Commands \StatusCommand ;
1214use Codemonster \Database \CLI \Commands \MakeMigrationCommand ;
15+ use Codemonster \Database \CLI \Commands \SeedCommand ;
16+ use Codemonster \Database \CLI \Commands \MakeSeedCommand ;
1317
1418class DatabaseCLIKernel
1519{
@@ -19,17 +23,31 @@ class DatabaseCLIKernel
1923
2024 protected Migrator $ migrator ;
2125
22- public function __construct (ConnectionInterface $ connection , ?MigrationPathResolver $ paths = null )
23- {
26+ protected SeedPathResolver $ seedPaths ;
27+
28+ protected SeederRunner $ seeder ;
29+
30+ public function __construct (
31+ ConnectionInterface $ connection ,
32+ ?MigrationPathResolver $ paths = null ,
33+ ?SeedPathResolver $ seedPaths = null
34+ ) {
2435 $ this ->paths = $ paths ?? new MigrationPathResolver ();
2536
2637 if (empty ($ this ->paths ->getPaths ())) {
2738 $ this ->paths ->addPath (getcwd () . DIRECTORY_SEPARATOR . 'database ' . DIRECTORY_SEPARATOR . 'migrations ' );
2839 }
2940
41+ $ this ->seedPaths = $ seedPaths ?? new SeedPathResolver ();
42+
43+ if (empty ($ this ->seedPaths ->getPaths ())) {
44+ $ this ->seedPaths ->addPath (getcwd () . DIRECTORY_SEPARATOR . 'database ' . DIRECTORY_SEPARATOR . 'seeds ' );
45+ }
46+
3047 $ repository = new MigrationRepository ($ connection );
3148
3249 $ this ->migrator = new Migrator ($ repository , $ connection , $ this ->paths );
50+ $ this ->seeder = new SeederRunner ($ connection , $ this ->seedPaths );
3351 $ this ->commands = new CommandRegistry ();
3452
3553 $ this ->registerDefaultCommands ();
@@ -41,6 +59,8 @@ protected function registerDefaultCommands(): void
4159 $ this ->commands ->register (new RollbackCommand ($ this ->migrator ));
4260 $ this ->commands ->register (new StatusCommand ($ this ->migrator ));
4361 $ this ->commands ->register (new MakeMigrationCommand ($ this ->paths ));
62+ $ this ->commands ->register (new SeedCommand ($ this ->seeder ));
63+ $ this ->commands ->register (new MakeSeedCommand ($ this ->seedPaths ));
4464 }
4565
4666 public function handle (array $ argv ): int
@@ -58,8 +78,18 @@ public function getPathResolver(): MigrationPathResolver
5878 return $ this ->paths ;
5979 }
6080
81+ public function getSeedPathResolver (): SeedPathResolver
82+ {
83+ return $ this ->seedPaths ;
84+ }
85+
6186 public function getMigrator (): Migrator
6287 {
6388 return $ this ->migrator ;
6489 }
90+
91+ public function getSeeder (): SeederRunner
92+ {
93+ return $ this ->seeder ;
94+ }
6595}
0 commit comments