|
6 | 6 | set_time_limit(0); |
7 | 7 | ini_set('memory_limit','1000M'); |
8 | 8 | ini_set('display_errors', 'stderr'); |
9 | | -if(php_sapi_name() == 'cli') { |
10 | | - if(count($argv) < 2) { |
11 | | - echo "error: not enough arguments"; |
12 | | - } elseif ($argv[1] == 'generate') { |
13 | | - array_shift($argv); |
14 | | - array_shift($argv); |
15 | | - |
16 | | - $verbose = false; |
17 | | - if(count($argv) > 0 && $argv[0] == '-verbose') { |
18 | | - array_shift($argv); |
19 | | - $verbose = true; |
20 | | - } |
21 | 9 |
|
22 | | - $phpCompletePsr = new IndexGenerator($verbose); |
| 10 | +/** @var $command \Command\CommandInterface */ |
23 | 11 |
|
24 | | - $plugins = explode("-u", implode("", $argv)); |
25 | | - foreach ($plugins as $pluginFile) { |
26 | | - if(empty($pluginFile)) { |
27 | | - continue; |
28 | | - } |
29 | | - $phpCompletePsr->addPlugin(trim($pluginFile)); |
30 | | - } |
| 12 | +$arguments = []; |
31 | 13 |
|
32 | | - $index = $phpCompletePsr->generateIndex(); |
33 | | - |
34 | | - $jsonIndex = json_encode($index); |
35 | | - $lastJsonError = json_last_error(); |
36 | | - if($lastJsonError != JSON_ERROR_NONE) { |
37 | | - printJsonError($lastJsonError); |
38 | | - exit; |
39 | | - } |
40 | | - |
41 | | - $phpCompletePsr->writeToFile($phpCompletePsr->getIndexFileName(), $jsonIndex); |
42 | | - $phpCompletePsr->writeToFile($phpCompletePsr->getReportFileName(), implode("\n", $phpCompletePsr->getInvalidClasses())); |
| 14 | +if(php_sapi_name() == 'cli') { |
| 15 | + if(count($argv) < 2) { |
| 16 | + $command = new \Command\ErrorCommand; |
| 17 | + } elseif ($argv[1] == 'generate') { |
| 18 | + $command = new \Command\GenerateCommand; |
43 | 19 | } else if($argv[1] == 'update') { |
44 | | - array_shift($argv); |
45 | | - array_shift($argv); |
46 | | - $file = array_shift($argv); |
47 | | - $cacheFileName = array_shift($argv); |
48 | | - $verbose = false; |
49 | | - |
50 | | - $p = new IndexGenerator($verbose); |
51 | | - $plugins = explode("-u", implode("", $argv)); |
52 | | - foreach ($plugins as $pluginFile) { |
53 | | - if(empty($pluginFile)) { |
54 | | - continue; |
55 | | - } |
56 | | - $p->addPlugin($pluginFile); |
57 | | - } |
58 | | - |
59 | | - $p->writeUpdatedClassInfo($file, $cacheFileName); |
60 | | - //echo "Time Elapsed: ".(microtime(true) - $time)."s\n"; |
61 | | - //echo "highest memory ". memory_get_peak_usage(); |
| 20 | + $command = new \Command\UpdateCommand; |
62 | 21 | } else { |
63 | | - echo "not a valid argument"; |
64 | | - exit; |
| 22 | + $command = new \Command\ErrorCommand; |
65 | 23 | } |
66 | 24 | } else { |
67 | | - exit; |
68 | | -} |
69 | | - |
70 | | -function printJsonError($errorCode) |
71 | | -{ |
72 | | - switch (json_last_error()) { |
73 | | - case JSON_ERROR_NONE: |
74 | | - echo ' - No errors'; |
75 | | - break; |
76 | | - case JSON_ERROR_DEPTH: |
77 | | - echo ' - Maximum stack depth exceeded'; |
78 | | - break; |
79 | | - case JSON_ERROR_STATE_MISMATCH: |
80 | | - echo ' - Underflow or the modes mismatch'; |
81 | | - break; |
82 | | - case JSON_ERROR_CTRL_CHAR: |
83 | | - echo ' - Unexpected control character found'; |
84 | | - break; |
85 | | - case JSON_ERROR_SYNTAX: |
86 | | - echo ' - Syntax error, malformed JSON'; |
87 | | - break; |
88 | | - case JSON_ERROR_UTF8: |
89 | | - echo ' - Malformed UTF-8 characters, possibly incorrectly encoded'; |
90 | | - break; |
91 | | - default: |
92 | | - echo ' - Unknown error'; |
93 | | - break; |
94 | | - } |
95 | | - echo "\n"; |
| 25 | + $command = new \Command\ErrorCommand; |
96 | 26 | } |
97 | 27 |
|
| 28 | +$command->run($arguments); |
0 commit comments