33namespace App ;
44
55use Docopt ;
6-
7- function parseFile (string $ filename ): array
8- {
9- $ handle = fopen ($ filename , "r " );
10- $ result = json_decode (fread ($ handle , 4096 ));
11- fclose ($ handle );
12-
13- $ keys = (get_object_vars ($ result ));
14-
15- return $ keys ;
16- }
6+ use App \OutputInterface ;
7+ use App \CommandInterface ;
8+ use App \Invoker ;
9+ use App \Command ;
1710
1811function runGendiff (): void
1912{
13+
2014 $ doc = <<<'DOCOPT'
2115 gendiff -h
2216
@@ -34,26 +28,16 @@ function runGendiff(): void
3428
3529 DOCOPT;
3630
37- $ cliData = Docopt::handle ($ doc , array ('version ' => '1.0.6 ' ));
38- /*
39- foreach ($cliData as $k => $v) {
40- print_r($k . ': ' . json_encode($v) . PHP_EOL);
41- }
42- */
43- if (file_exists ($ cliData ['FILE1 ' ])) {
44- if (file_exists ($ cliData ['FILE2 ' ])) {
45- $ file1Content = parseFile ($ cliData ['FILE1 ' ]);
46- $ file2Content = parseFile ($ cliData ['FILE2 ' ]);
47-
48- print_r ("File1 content: \n" );
49- print_r ($ file1Content );
50- print_r ("File2 content: \n" );
51- print_r ($ file2Content );
52- } else {
53- print_r ("File {$ cliData ['FILE2 ' ]} not exists " );
31+ $ output = new class implements OutputInterface
32+ {
33+ public function parseCommandData (string $ docopt ): object
34+ {
35+ return Docopt::handle ($ docopt , array ('version ' => '1.0.6 ' ));
5436 }
55- } else {
56- print_r ("File {$ cliData ['FILE1 ' ]} not exists \n" );
57- runGendiff ();
58- }
37+ };
38+
39+ $ command = new Command ($ output , $ doc );
40+ $ invoker = new Invoker ();
41+ $ invoker ->setCommand ($ command );
42+ $ invoker ->run ();
5943}
0 commit comments