88
99namespace Inhere \Console \IO \Input ;
1010
11+ use Inhere \Console \Contract \InputFlagInterface ;
1112use Inhere \Console \IO \Input ;
1213
1314/**
14- * Class InputItem
15+ * Class InputFlag
1516 * - definition a input item(option|argument)
1617 *
1718 * @package Inhere\Console\IO\Input
1819 */
19- class InputItem
20+ abstract class InputFlag implements InputFlagInterface
2021{
2122 /**
2223 * @var string
@@ -34,11 +35,11 @@ class InputItem
3435 private $ mode ;
3536
3637 /**
37- * The argument data type. (eg: 'string', 'array', 'mixed')
38+ * The argument data type. (eg: 'int', 'bool', ' string', 'array', 'mixed')
3839 *
3940 * @var string
4041 */
41- private $ type ;
42+ private $ type = '' ;
4243
4344 /**
4445 * The default value
@@ -79,14 +80,25 @@ public function __construct(string $name, int $mode = 0, string $description = '
7980 $ this ->setDescription ($ description );
8081 }
8182
83+ /******************************************************************
84+ * mode value
85+ *****************************************************************/
86+
8287 /**
88+ * @param int $mode
89+ *
8390 * @return bool
8491 */
85- public function isArray ( ): bool
92+ public function hasMode ( int $ mode ): bool
8693 {
87- return $ this ->mode === Input:: ARG_IS_ARRAY ;
94+ return ( $ this ->mode & $ mode ) > 0 ;
8895 }
8996
97+
98+ /******************************************************************
99+ *
100+ *****************************************************************/
101+
90102 /**
91103 * @return string
92104 */
@@ -166,4 +178,21 @@ public function setDescription(string $description): void
166178 {
167179 $ this ->description = $ description ;
168180 }
181+
182+ /**
183+ * @return array
184+ */
185+ public function toArray (): array
186+ {
187+ return [
188+ 'name ' => $ this ->name ,
189+ 'mode ' => $ this ->mode ,
190+ 'type ' => $ this ->type ,
191+ 'default ' => $ this ->default ,
192+ 'isArray ' => $ this ->isArray (),
193+ 'isOptional ' => $ this ->isOptional (),
194+ 'isRequired ' => $ this ->isRequired (),
195+ 'description ' => $ this ->description ,
196+ ];
197+ }
169198}
0 commit comments