@@ -34,19 +34,19 @@ abstract class AbstractApp
3434 const ON_NOT_FOUND = 'notFound ' ;
3535
3636 /**
37- * app config
37+ * app meta config
3838 * @var array
3939 */
40- private $ config = [
41- 'env ' => 'pdt ' , // dev test pdt
42- 'debug ' => false ,
40+ private $ meta = [
4341 'name ' => 'My Console ' ,
4442 'version ' => '0.5.1 ' ,
4543 'publishAt ' => '2017.03.24 ' ,
4644 'rootPath ' => '' ,
4745 'hideRootPath ' => true ,
48- 'charset ' => 'UTF-8 ' ,
49- 'timeZone ' => 'Asia/Shanghai ' ,
46+ // 'env' => 'pdt', // dev test pdt
47+ // 'debug' => false,
48+ // 'charset' => 'UTF-8',
49+ // 'timeZone' => 'Asia/Shanghai',
5050 ];
5151
5252 /**
@@ -58,6 +58,14 @@ abstract class AbstractApp
5858 'list ' => 'List all group and independent commands ' ,
5959 ];
6060
61+ /**
62+ * @var array
63+ */
64+ protected static $ internalOptions = [
65+ '--debug ' => 'setting the application runtime debug level ' ,
66+ '--no-color ' => 'setting no color for message output ' ,
67+ ];
68+
6169 /**
6270 * @var array
6371 */
@@ -80,14 +88,14 @@ abstract class AbstractApp
8088
8189 /**
8290 * App constructor.
83- * @param array $config
91+ * @param array $meta
8492 * @param Input $input
8593 * @param Output $output
8694 */
87- public function __construct (array $ config = [], Input $ input = null , Output $ output = null )
95+ public function __construct (array $ meta = [], Input $ input = null , Output $ output = null )
8896 {
8997 $ this ->runtimeCheck ();
90- $ this ->setConfig ( $ config );
98+ $ this ->setMeta ( $ meta );
9199
92100 $ this ->input = $ input ?: new Input ();
93101 $ this ->output = $ output ?: new Output ();
@@ -118,7 +126,7 @@ protected function init()
118126
119127 protected function prepareRun ()
120128 {
121- date_default_timezone_set ($ this ->config ('timeZone ' , 'UTC ' ));
129+ // date_default_timezone_set($this->config('timeZone', 'UTC'));
122130 }
123131
124132 /**
@@ -127,11 +135,9 @@ protected function prepareRun()
127135 */
128136 public function run ($ exit = true )
129137 {
130- $ this ->prepareRun ();
131-
132138 $ command = $ this ->input ->getCommand ();
133139
134- // like show help info
140+ $ this -> prepareRun ();
135141 $ this ->filterSpecialCommand ($ command );
136142
137143 // call 'onBeforeRun' service, if it is registered.
@@ -302,7 +308,7 @@ public function exceptionHandler($e)
302308 $ e ->getTraceAsString ()
303309 );
304310
305- if ($ this ->config ( 'hideRootPath ' ) && $ rootPath = $ this ->config ( 'rootPath ' ) ) {
311+ if ($ this ->meta [ 'hideRootPath ' ] && $ rootPath = $ this ->meta [ 'rootPath ' ] ) {
306312 $ message = str_replace ($ rootPath , '{ROOT} ' , $ message );
307313 }
308314
@@ -439,7 +445,8 @@ public function showCommandList($quit = true)
439445 //'There are all console controllers and independent commands.',
440446 'Group Commands:(by controller) ' => $ controllerArr ?: '... No register any group command(controller) ' ,
441447 'Independent Commands: ' => $ commandArr ?: '... No register any independent command ' ,
442- 'Internal Commands: ' => $ internalCommands
448+ 'Internal Commands: ' => $ internalCommands ,
449+ 'Internal Options: ' => self ::$ internalOptions
443450 ]);
444451
445452 $ this ->output ->write ("More please see: <cyan> $ script [controller|command] -h</cyan> " );
@@ -518,63 +525,31 @@ public function isInternalCommand(string $name): bool
518525 }
519526
520527 /**
521- * get/set config
522- * @param array|string $name
523- * @param mixed $default
524- * @return mixed
525- */
526- public function config ($ name , $ default = null )
527- {
528- // `$name` is array, set config.
529- if (is_array ($ name )) {
530- foreach ((array ) $ name as $ key => $ value ) {
531- $ this ->config [$ key ] = $ value ;
532- }
533-
534- return true ;
535- }
536-
537- // is string, get config
538- if (!is_string ($ name )) {
539- return $ default ;
540- }
541-
542- // allow get $config['top']['sub'] by 'top.sub'
543- if (strpos ($ name , '. ' ) > 1 ) {
544- $ nodes = array_filter (explode ('. ' , $ name ));
545-
546- return Helper::findValueByNodes ($ this ->config , $ nodes , $ default );
547- }
548-
549- return $ this ->config [$ name ] ?? $ default ;
550- }
551-
552- /**
553- * set config
554- * @param array $config
528+ * set meta info
529+ * @param array $meta
555530 */
556- public function setConfig ( $ config )
531+ public function setMeta ( array $ meta )
557532 {
558- if ($ config ) {
559- $ this ->config = array_merge ($ this ->config , (array )$ config );
533+ if ($ meta ) {
534+ $ this ->meta = array_merge ($ this ->meta , (array )$ meta );
560535 }
561536 }
562537
563538 /**
564- * get config
539+ * get meta
565540 * @return array
566541 */
567- public function getConfig ()
542+ public function getMeta ()
568543 {
569- return $ this ->config ;
544+ return $ this ->meta ;
570545 }
571546
572547 /**
573548 * is Debug
574- * @return boolean
549+ * @return boolean|int
575550 */
576- public function isDebug (): bool
551+ public function isDebug ()
577552 {
578- return ( bool ) $ this ->config ('debug ' );
553+ return $ this ->input -> getOpt ('debug ' );
579554 }
580555}
0 commit comments