@@ -46,57 +46,59 @@ final class InputParser
4646 */
4747 public static function fromArgv (array $ params , array $ config = []): array
4848 {
49- $ config = array_merge ([
49+ $ config = \ array_merge ([
5050 // List of parameters without values(bool option keys)
5151 'noValues ' => [], // ['debug', 'h']
5252 // Whether merge short-opts and long-opts
5353 'mergeOpts ' => false ,
54+ // want parsed opts
55+ 'wantParsedOpts ' => [],
5456 // list of params allow array.
5557 'arrayValues ' => [], // ['names', 'status']
5658 ], $ config );
5759
5860 $ args = $ sOpts = $ lOpts = [];
59- $ noValues = array_flip ((array )$ config ['noValues ' ]);
60- $ arrayValues = array_flip ((array )$ config ['arrayValues ' ]);
61+ $ noValues = \ array_flip ((array )$ config ['noValues ' ]);
62+ $ arrayValues = \ array_flip ((array )$ config ['arrayValues ' ]);
6163
6264 // each() will deprecated at 7.2. so,there use current and next instead it.
6365 // while (list(,$p) = each($params)) {
64- while (false !== ($ p = current ($ params ))) {
65- next ($ params );
66+ while (false !== ($ p = \ current ($ params ))) {
67+ \ next ($ params );
6668
6769 // is options
6870 if ($ p {0 } === '- ' ) {
6971 $ val = true ;
70- $ opt = substr ($ p , 1 );
72+ $ opt = \ substr ($ p , 1 );
7173 $ isLong = false ;
7274
7375 // long-opt: (--<opt>)
7476 if ($ opt {0 } === '- ' ) {
75- $ opt = substr ($ opt , 1 );
77+ $ opt = \ substr ($ opt , 1 );
7678 $ isLong = true ;
7779
7880 // long-opt: value specified inline (--<opt>=<value>)
79- if (strpos ($ opt , '= ' ) !== false ) {
80- list ($ opt , $ val ) = explode ('= ' , $ opt , 2 );
81+ if (\ strpos ($ opt , '= ' ) !== false ) {
82+ list ($ opt , $ val ) = \ explode ('= ' , $ opt , 2 );
8183 }
8284
8385 // short-opt: value specified inline (-<opt>=<value>)
8486 } elseif (isset ($ opt {1 }) && $ opt {1 } === '= ' ) {
85- list ($ opt , $ val ) = explode ('= ' , $ opt , 2 );
87+ list ($ opt , $ val ) = \ explode ('= ' , $ opt , 2 );
8688 }
8789
8890 // check if next parameter is a descriptor or a value
89- $ nxt = current ($ params );
91+ $ nxt = \ current ($ params );
9092
9193 // next elem is value. fix: allow empty string ''
9294 if ($ val === true && !isset ($ noValues [$ opt ]) && self ::nextIsValue ($ nxt )) {
9395 // list(,$val) = each($params);
9496 $ val = $ nxt ;
95- next ($ params );
97+ \ next ($ params );
9698
9799 // short-opt: bool opts. like -e -abc
98100 } elseif (!$ isLong && $ val === true ) {
99- foreach (str_split ($ opt ) as $ char ) {
101+ foreach (\ str_split ($ opt ) as $ char ) {
100102 $ sOpts [$ char ] = true ;
101103 }
102104
@@ -123,8 +125,8 @@ public static function fromArgv(array $params, array $config = []): array
123125 // arguments: param doesn't belong to any option, define it is args
124126 } else {
125127 // value specified inline (<arg>=<value>)
126- if (strpos ($ p , '= ' ) !== false ) {
127- list ($ name , $ val ) = explode ('= ' , $ p , 2 );
128+ if (\ strpos ($ p , '= ' ) !== false ) {
129+ list ($ name , $ val ) = \ explode ('= ' , $ p , 2 );
128130 $ args [$ name ] = self ::filterBool ($ val );
129131 } else {
130132 $ args [] = $ p ;
@@ -133,7 +135,7 @@ public static function fromArgv(array $params, array $config = []): array
133135 }
134136
135137 if ($ config ['mergeOpts ' ]) {
136- return [$ args , array_merge ($ sOpts , $ lOpts )];
138+ return [$ args , \ array_merge ($ sOpts , $ lOpts )];
137139 }
138140
139141 return [$ args , $ sOpts , $ lOpts ];
0 commit comments