99use DragonCode \LaravelActions \Contracts \Notification ;
1010use DragonCode \LaravelActions \Helpers \Config ;
1111use DragonCode \LaravelActions \Helpers \Git ;
12+ use DragonCode \LaravelActions \Helpers \Sorter ;
1213use DragonCode \LaravelActions \Repositories \ActionRepository ;
1314use DragonCode \LaravelActions \Services \Migrator ;
1415use DragonCode \LaravelActions \Values \Options ;
15- use DragonCode \Support \Facades \Helpers \Arr ;
1616use DragonCode \Support \Facades \Helpers \Str ;
1717use DragonCode \Support \Filesystem \File ;
18- use DragonCode \Support \Helpers \Ables \Arrayable ;
1918use Illuminate \Console \OutputStyle ;
2019use Illuminate \Contracts \Events \Dispatcher ;
2120use Symfony \Component \Console \Input \InputInterface ;
@@ -36,42 +35,25 @@ public function __construct(
3635 protected File $ file ,
3736 protected Migrator $ migrator ,
3837 protected Notification $ notification ,
39- protected Dispatcher $ events
38+ protected Dispatcher $ events ,
39+ protected Sorter $ sorter
4040 ) {
4141 $ this ->notification ->setOutput ($ this ->output );
4242 $ this ->repository ->setConnection ($ this ->options ->connection );
4343 $ this ->migrator ->setConnection ($ this ->options ->connection )->setOutput ($ this ->output );
4444 }
4545
46- protected function getFiles (? Closure $ filter = null , ? string $ path = null , bool $ realpath = false , bool $ fullpath = false , bool $ withExtension = true ): array
46+ protected function getFiles (string $ path, ? Closure $ filter = null ): array
4747 {
48- $ path = $ this -> getActionsPath ($ path , $ realpath );
48+ $ file = Str:: finish ($ path , ' .php ' );
4949
50- $ names = $ this ->file ->exists ($ path ) ? [$ path ] : $ this ->file ->allPaths ($ path , $ filter , true );
51-
52- return Arr::of ($ names )
53- ->when (
54- ! $ fullpath ,
55- fn (Arrayable $ array ) => $ array
56- ->map (fn (string $ value ) => Str::of (realpath ($ value ))->after (realpath ($ path ))->ltrim ('\\/ ' )->toString ())
57- )
58- ->when (
59- ! $ withExtension ,
60- fn (Arrayable $ array ) => $ array
61- ->map (fn (string $ value ) => Str::before ($ value , '.php ' ))
62- )
63- ->toArray ();
64- }
65-
66- protected function getActionsPath (?string $ path = null , bool $ realpath = false ): string
67- {
68- $ path = $ realpath ? $ path : $ this ->config ->path ($ path );
69-
70- if (! is_dir ($ path ) && ! Str::endsWith ($ path , '.php ' )) {
71- return $ this ->file ->exists ($ path . '.php ' ) ? $ path . '.php ' : $ path ;
50+ if ($ this ->file ->exists ($ file ) && $ this ->file ->isFile ($ file )) {
51+ return [$ file ];
7252 }
7353
74- return $ path ;
54+ return $ this ->sorter ->byValues (
55+ $ this ->file ->names ($ path , $ filter , true )
56+ );
7557 }
7658
7759 protected function runCommand (string $ command , array $ options = []): void
0 commit comments