44
55use Illuminate \Support \Arr ;
66use RonasIT \Support \Events \SuccessCreateMessage ;
7+ use RonasIT \Support \Events \WarningEvent ;
78use RonasIT \Support \Exceptions \EntityCreateException ;
89
910class SeederGenerator extends EntityGenerator
@@ -15,13 +16,15 @@ public function __construct()
1516 {
1617 parent ::__construct ();
1718
18- $ this ->seedsPath = Arr::get ($ this ->paths , 'seeders ' , 'database/seeders ' );
19- $ this ->databaseSeederPath = Arr::get ($ this ->paths , 'database_seeder ' , 'database/seeders/DatabaseSeeder.php ' );
19+ $ this ->seedsPath = base_path ( Arr::get ($ this ->paths , 'seeders ' , 'database/seeders ' ) );
20+ $ this ->databaseSeederPath = base_path ( Arr::get ($ this ->paths , 'database_seeder ' , 'database/seeders/DatabaseSeeder.php ' ) );
2021 }
2122
2223 public function generate (): void
2324 {
24- $ this ->checkConfigs ();
25+ if (!file_exists ($ this ->seedsPath )) {
26+ mkdir ($ this ->seedsPath );
27+ }
2528
2629 if (!file_exists ($ this ->databaseSeederPath )) {
2730 list ($ basePath , $ databaseSeederDir ) = extract_last_part ($ this ->databaseSeederPath , '/ ' );
@@ -33,10 +36,6 @@ public function generate(): void
3336 $ this ->createDatabaseSeeder ();
3437 }
3538
36- if (!is_dir ($ this ->seedsPath )) {
37- mkdir ($ this ->seedsPath );
38- }
39-
4039 $ this ->createEntitySeeder ();
4140
4241 $ this ->appendSeederToList ();
@@ -46,6 +45,15 @@ protected function createDatabaseSeeder(): void
4645 {
4746 $ stubPath = config ('entity-generator.stubs.database_empty_seeder ' );
4847
48+ //@TODO: remove after implementing https://github.com/RonasIT/laravel-entity-generator/issues/93
49+ if ($ stubPath === 'entity-generator::database_seed_empty ' ) {
50+ $ stubPath = 'entity-generator::database_empty_seeder ' ;
51+
52+ $ message = "You are using the deprecated value for 'entity-generator.stubs.database_empty_seeder' config. Please use 'entity-generator::database_empty_seeder'. " ;
53+
54+ event (new WarningEvent ($ message ));
55+ }
56+
4957 $ content = "<?php \n\n" . view ($ stubPath , [
5058 'namespace ' => $ this ->getOrCreateNamespace ('seeders ' )
5159 ])->render ();
@@ -70,7 +78,7 @@ protected function createEntitySeeder(): void
7078 'modelsNamespace ' => $ this ->getOrCreateNamespace ('models ' )
7179 ])->render ();
7280
73- $ seederPath = base_path ( "{$ this ->seedsPath }/ {$ this ->model }Seeder.php " ) ;
81+ $ seederPath = "{$ this ->seedsPath }/ {$ this ->model }Seeder.php " ;
7482
7583 file_put_contents ($ seederPath , $ content );
7684
@@ -83,20 +91,10 @@ protected function appendSeederToList(): void
8391 {
8492 $ content = file_get_contents ($ this ->databaseSeederPath );
8593
86- $ insertContent = "\n \$this->call( {$ this ->model }Seeder::class); \n } \n} " ;
94+ $ insertContent = " \$this->call( {$ this ->model }Seeder::class); \n } \n} " ;
8795
8896 $ fixedContent = preg_replace ('/\}\s*\}\s*\z/ ' , $ insertContent , $ content );
8997
9098 file_put_contents ($ this ->databaseSeederPath , $ fixedContent );
9199 }
92-
93- protected function checkConfigs (): void
94- {
95- if (empty (config ('entity-generator.stubs.seeder ' )) || empty (config ('entity-generator.stubs.legacy_seeder ' ))) {
96- throw new EntityCreateException ('
97- Looks like you have deprecated configs.
98- Please follow instructions(https://github.com/RonasIT/laravel-entity-generator/blob/master/ReadMe.md#13)
99- ' );
100- }
101- }
102100}
0 commit comments