37
37
* Class App - A lite CLI Application
38
38
*
39
39
* @package Inhere\Console
40
+ * @deprecated please use package: toolkit/pflag
40
41
*/
41
42
class App
42
43
{
43
- /** @var self */
44
- public static $ global ;
44
+ /** @var self|null */
45
+ public static ? self $ global = null ;
45
46
46
47
private const COMMAND_CONFIG = [
47
48
'desc ' => '' ,
@@ -50,12 +51,12 @@ class App
50
51
];
51
52
52
53
/** @var string Current dir */
53
- private $ pwd ;
54
+ private string $ pwd ;
54
55
55
56
/**
56
57
* @var array
57
58
*/
58
- protected $ params = [
59
+ protected array $ params = [
59
60
'name ' => 'My application ' ,
60
61
'desc ' => 'My command line application ' ,
61
62
'version ' => '0.2.1 '
@@ -64,37 +65,37 @@ class App
64
65
/**
65
66
* @var array Parsed from `arg0 name=val var2=val2`
66
67
*/
67
- private $ args ;
68
+ private mixed $ args ;
68
69
69
70
/**
70
71
* @var array Parsed from `--name=val --var2=val2 -d`
71
72
*/
72
- private $ opts ;
73
+ private mixed $ opts ;
73
74
74
75
/**
75
76
* @var string
76
77
*/
77
- private $ script ;
78
+ private mixed $ script ;
78
79
79
80
/**
80
81
* @var string
81
82
*/
82
- private $ command = '' ;
83
+ private string $ command = '' ;
83
84
84
85
/**
85
86
* @var array User add commands
86
87
*/
87
- private $ commands = [];
88
+ private array $ commands = [];
88
89
89
90
/**
90
91
* @var array Command messages for the commands
91
92
*/
92
- private $ messages = [];
93
+ private array $ messages = [];
93
94
94
95
/**
95
96
* @var int
96
97
*/
97
- private $ keyWidth = 12 ;
98
+ private int $ keyWidth = 12 ;
98
99
99
100
/**
100
101
* @return static
@@ -233,7 +234,7 @@ public function stop(int $code = 0): void
233
234
* @return mixed
234
235
* @throws InvalidArgumentException
235
236
*/
236
- public function runHandler (string $ command , $ handler )
237
+ public function runHandler (string $ command , mixed $ handler ): mixed
237
238
{
238
239
if (is_string ($ handler )) {
239
240
// function name
@@ -315,19 +316,19 @@ public function addByConfig(callable $handler, array $config): void
315
316
/**
316
317
* @param string $command
317
318
* @param callable $handler
318
- * @param null| array|string $config
319
+ * @param array|string|null $config
319
320
*/
320
- public function add (string $ command , callable $ handler , $ config = null ): void
321
+ public function add (string $ command , callable $ handler , array | string $ config = null ): void
321
322
{
322
323
$ this ->addCommand ($ command , $ handler , $ config );
323
324
}
324
325
325
326
/**
326
327
* @param string $command
327
328
* @param callable $handler
328
- * @param null| array|string $config
329
+ * @param array|string|null $config
329
330
*/
330
- public function addCommand (string $ command , callable $ handler , $ config = null ): void
331
+ public function addCommand (string $ command , callable $ handler , array | string $ config = null ): void
331
332
{
332
333
if (!$ command ) {
333
334
throw new InvalidArgumentException ('Invalid arguments for add command ' );
@@ -463,45 +464,45 @@ public function displayCommandHelp(string $name): void
463
464
}
464
465
465
466
/**
466
- * @param string| int $name
467
- * @param mixed $default
467
+ * @param int|string $name
468
+ * @param mixed|null $default
468
469
*
469
470
* @return mixed|null
470
471
*/
471
- public function getArg ($ name , $ default = null )
472
+ public function getArg (int | string $ name , mixed $ default = null ): mixed
472
473
{
473
474
return $ this ->args [$ name ] ?? $ default ;
474
475
}
475
476
476
477
/**
477
- * @param string| int $name
478
+ * @param int|string $name
478
479
* @param int $default
479
480
*
480
481
* @return int
481
482
*/
482
- public function getIntArg ($ name , int $ default = 0 ): int
483
+ public function getIntArg (int | string $ name , int $ default = 0 ): int
483
484
{
484
485
return (int )$ this ->getArg ($ name , $ default );
485
486
}
486
487
487
488
/**
488
- * @param string| int $name
489
+ * @param int|string $name
489
490
* @param string $default
490
491
*
491
492
* @return string
492
493
*/
493
- public function getStrArg ($ name , string $ default = '' ): string
494
+ public function getStrArg (int | string $ name , string $ default = '' ): string
494
495
{
495
496
return (string )$ this ->getArg ($ name , $ default );
496
497
}
497
498
498
499
/**
499
500
* @param string $name
500
- * @param mixed $default
501
+ * @param mixed|null $default
501
502
*
502
503
* @return mixed|null
503
504
*/
504
- public function getOpt (string $ name , $ default = null )
505
+ public function getOpt (string $ name , mixed $ default = null ): mixed
505
506
{
506
507
return $ this ->opts [$ name ] ?? $ default ;
507
508
}
@@ -688,7 +689,7 @@ public function setMetas(array $params): void
688
689
*
689
690
* @return mixed|string|null
690
691
*/
691
- public function getParam (string $ key , $ default = null )
692
+ public function getParam (string $ key , $ default = null ): mixed
692
693
{
693
694
return $ this ->params [$ key ] ?? $ default ;
694
695
}
@@ -697,7 +698,7 @@ public function getParam(string $key, $default = null)
697
698
* @param string $key
698
699
* @param mixed $val
699
700
*/
700
- public function setParam (string $ key , $ val ): void
701
+ public function setParam (string $ key , mixed $ val ): void
701
702
{
702
703
$ this ->params [$ key ] = $ val ;
703
704
}
0 commit comments