44
55namespace Rector \Jack \DependencyInjection ;
66
7- use Illuminate \Container \Container ;
8- use Rector \Jack \Console \JackConsoleApplication ;
9- use Symfony \Component \Console \Application ;
10- use Symfony \Component \Finder \Finder ;
11- use Webmozart \Assert \Assert ;
7+ use Entropy \Console \CommandRegistry ;
8+ use Entropy \Console \Contract \CommandInterface ;
9+ use Entropy \Container \Container ;
1210
1311final class ContainerFactory
1412{
@@ -19,57 +17,12 @@ public function create(): Container
1917 {
2018 $ container = new Container ();
2119
22- // console
23- $ container ->singleton (Application::class, function (Container $ container ): Application {
24- $ jackConsoleApplication = new JackConsoleApplication ('Rector Jack ' );
25-
26- $ commandClasses = $ this ->findCommandClasses ();
27-
28- // register commands
29- foreach ($ commandClasses as $ commandClass ) {
30- $ command = $ container ->make ($ commandClass );
31- $ jackConsoleApplication ->add ($ command );
32- }
33-
34- // remove basic command to make output clear
35- $ this ->hideDefaultCommands ($ jackConsoleApplication );
36-
37- return $ jackConsoleApplication ;
20+ // @todo avoid need of this
21+ $ container ->service (CommandRegistry::class, function (Container $ container ): CommandRegistry {
22+ $ commands = $ container ->findByContract (CommandInterface::class);
23+ return new CommandRegistry ($ commands );
3824 });
3925
4026 return $ container ;
4127 }
42-
43- public function hideDefaultCommands (Application $ application ): void
44- {
45- $ application ->get ('list ' )
46- ->setHidden (true );
47- $ application ->get ('completion ' )
48- ->setHidden (true );
49- $ application ->get ('help ' )
50- ->setHidden (true );
51- }
52-
53- /**
54- * @return string[]
55- */
56- private function findCommandClasses (): array
57- {
58- $ commandFinder = Finder::create ()
59- ->files ()
60- ->name ('*Command.php ' )
61- ->in (__DIR__ . '/../Command ' );
62-
63- $ commandClasses = [];
64- foreach ($ commandFinder as $ commandFile ) {
65- $ commandClass = 'Rector \\Jack \\Command \\' . $ commandFile ->getBasename ('.php ' );
66-
67- // make sure it exists
68- Assert::classExists ($ commandClass );
69-
70- $ commandClasses [] = $ commandClass ;
71- }
72-
73- return $ commandClasses ;
74- }
7528}
0 commit comments