1010
1111use inhere \console \io \Input ;
1212use inhere \console \io \Output ;
13+ use inhere \console \utils \TraitInputOutput ;
1314
1415/**
1516 * Class AbstractApp
1617 * @package inhere\console
1718 */
1819abstract class AbstractApp
1920{
21+ use TraitInputOutput;
22+
2023 // event name list
2124 const ON_BEFORE_RUN = 'beforeRun ' ;
2225 const ON_AFTER_RUN = 'afterRun ' ;
@@ -47,16 +50,6 @@ abstract class AbstractApp
4750 'timeZone ' => 'Asia/Shanghai ' ,
4851 ];
4952
50- /**
51- * @var Input
52- */
53- public $ input ;
54-
55- /**
56- * @var Output
57- */
58- public $ output ;
59-
6053 /**
6154 * @var array
6255 */
@@ -161,7 +154,7 @@ public function stop($code = 0)
161154 * @param string $controller The controller class
162155 * @return static
163156 */
164- public function controller ($ name , $ controller )
157+ public function controller (string $ name , string $ controller )
165158 {
166159 if (!$ name || !$ controller ) {
167160 throw new \InvalidArgumentException ('Parameters are not allowed to is empty! ' );
@@ -194,7 +187,7 @@ public function controllers(array $controllers)
194187 * @param string|\Closure $handler
195188 * @return $this
196189 */
197- public function command ($ name , $ handler )
190+ public function command (string $ name , $ handler )
198191 {
199192 if (!$ name || !$ handler ) {
200193 throw new \InvalidArgumentException ('Parameters are not allowed to is empty! ' );
@@ -221,7 +214,7 @@ public function commands(array $commands)
221214 /**
222215 * @return array
223216 */
224- public static function hooks ()
217+ public static function hooks (): array
225218 {
226219 return array_keys (self ::$ hooks );
227220 }
@@ -230,7 +223,7 @@ public static function hooks()
230223 * @param $event
231224 * @param callable $handler
232225 */
233- public function on ($ event , callable $ handler )
226+ public function on (string $ event , callable $ handler )
234227 {
235228 if (isset (self ::$ hooks [$ event ])) {
236229 self ::$ hooks [$ event ] = $ handler ;
@@ -240,7 +233,7 @@ public function on($event, callable $handler)
240233 /**
241234 * @return array
242235 */
243- public function getInternalCommands ()
236+ public function getInternalCommands (): array
244237 {
245238 return $ this ->internalCommands ;
246239 }
@@ -249,7 +242,7 @@ public function getInternalCommands()
249242 * @param $name
250243 * @return bool
251244 */
252- public function isInternalCommand ($ name )
245+ public function isInternalCommand (string $ name ): bool
253246 {
254247 return isset ($ this ->internalCommands [$ name ]);
255248 }
@@ -303,7 +296,7 @@ public function setConfig(array $config)
303296 * get config
304297 * @return array
305298 */
306- public function getConfig ()
299+ public function getConfig (): array
307300 {
308301 return $ this ->config ;
309302 }
@@ -312,44 +305,16 @@ public function getConfig()
312305 * is Debug
313306 * @return boolean
314307 */
315- public function isDebug ()
308+ public function isDebug (): bool
316309 {
317310 return (bool )$ this ->config ['debug ' ];
318311 }
319312
320313 /**
321- * @return Input
322- */
323- public function getInput ()
324- {
325- return $ this ->input ;
326- }
327-
328- /**
329- * @param Input $input
330- */
331- public function setInput (Input $ input )
332- {
333- $ this ->input = $ input ;
334- }
335-
336- /**
337- * @return Output
338- */
339- public function getOutput ()
340- {
341- return $ this ->output ;
342- }
343-
344- /**
345- * @param Output $output
314+ * @param $name
315+ * @param bool $isGroup
346316 */
347- public function setOutput (Output $ output )
348- {
349- $ this ->output = $ output ;
350- }
351-
352- protected function checkName ($ name , $ isGroup = false )
317+ protected function checkName (string $ name , $ isGroup = false )
353318 {
354319 $ pattern = $ isGroup ? '/^[a-z][\w-]+$/ ' : '/^[a-z][\w-]*:?([a-z][\w-]+)?$/ ' ;
355320
0 commit comments