File tree Expand file tree Collapse file tree 3 files changed +41
-3
lines changed Expand file tree Collapse file tree 3 files changed +41
-3
lines changed Original file line number Diff line number Diff line change 23
23
// 'user'
24
24
// ]
25
25
],
26
-
26
+
27
+ /*
28
+ * If you want to see only specific models, specify them here using fully qualified
29
+ * classnames.
30
+ *
31
+ * Note: that if this array is filled, the 'ignore' array will not be used.
32
+ */
33
+ 'whitelist ' => [
34
+ // App\User::class,
35
+ // App\Post::class,
36
+ ],
37
+
27
38
/*
28
39
* If true, all directories specified will be scanned recursively for models.
29
40
* Set this to false if you prefer to explicitly define each directory that should
Original file line number Diff line number Diff line change @@ -31,16 +31,25 @@ public function getModelsInDirectory(string $directory): Collection
31
31
$ this ->filesystem ->files ($ directory );
32
32
33
33
$ ignoreModels = array_filter (config ('erd-generator.ignore ' , []), 'is_string ' );
34
+ $ whitelistModels = array_filter (config ('erd-generator.whitelist ' , []), 'is_string ' );
34
35
35
- return Collection::make ($ files )->filter (function ($ path ) {
36
+ $ collection = Collection::make ($ files )->filter (function ($ path ) {
36
37
return Str::endsWith ($ path , '.php ' );
37
38
})->map (function ($ path ) {
38
39
return $ this ->getFullyQualifiedClassNameFromFile ($ path );
39
40
})->filter (function (string $ className ) {
40
41
return !empty ($ className )
41
42
&& is_subclass_of ($ className , EloquentModel::class)
42
43
&& ! (new ReflectionClass ($ className ))->isAbstract ();
43
- })->diff ($ ignoreModels )->sort ();
44
+ });
45
+
46
+ if (!count ($ whitelistModels )) {
47
+ return $ collection ->diff ($ ignoreModels )->sort ();
48
+ }
49
+
50
+ return $ collection ->filter (function (string $ className ) use ($ whitelistModels ) {
51
+ return in_array ($ className , $ whitelistModels );
52
+ });
44
53
}
45
54
46
55
protected function getFullyQualifiedClassNameFromFile (string $ path ): string
Original file line number Diff line number Diff line change @@ -46,4 +46,22 @@ public function it_will_ignore_a_model_if_it_is_excluded_on_config()
46
46
$ classNames ->values ()->all ()
47
47
);
48
48
}
49
+
50
+ /** @test */
51
+ public function it_will_only_return_models_in_whitelist_if_present ()
52
+ {
53
+ $ this ->app ['config ' ]->set ('erd-generator.whitelist ' , [
54
+ Avatar::class,
55
+ ]);
56
+
57
+ $ finder = new ModelFinder (app ()->make ('files ' ));
58
+
59
+ $ classNames = $ finder ->getModelsInDirectory (__DIR__ . "/Models " );
60
+
61
+ $ this ->assertCount (1 , $ classNames );
62
+ $ this ->assertEquals (
63
+ [Avatar::class],
64
+ $ classNames ->values ()->all ()
65
+ );
66
+ }
49
67
}
You can’t perform that action at this time.
0 commit comments