@@ -87,21 +87,6 @@ abstract class AbstractApplication implements ApplicationInterface
8787 */
8888 private $ errorHandler ;
8989
90- /**
91- * @var array Some metadata for command
92- * - description
93- */
94- private $ commandsMeta = [];
95-
96- /** @var array Save command aliases */
97- private $ commandAliases = [];
98-
99- /** @var array The independent commands */
100- protected $ commands = [];
101-
102- /** @var array The group commands(controller) */
103- protected $ controllers = [];
104-
10590 /**
10691 * Class constructor.
10792 * @param array $config
@@ -219,13 +204,6 @@ public function run(bool $exit = true)
219204 return $ result ;
220205 }
221206
222- /**
223- * dispatch command
224- * @param string $command A command name
225- * @return int|mixed
226- */
227- abstract protected function dispatch (string $ command );
228-
229207 protected function afterRun (): void
230208 {
231209 }
@@ -366,62 +344,20 @@ protected function filterSpecialCommand(string $command): bool
366344 return true ;
367345 }
368346
369- /**
370- * @param $name
371- * @param bool $isGroup
372- * @throws \InvalidArgumentException
373- */
374- protected function validateName (string $ name , bool $ isGroup = false ): void
375- {
376- $ pattern = $ isGroup ? '/^[a-z][\w-]+$/ ' : '/^[a-z][\w-]*:?([a-z][\w-]+)?$/ ' ;
377-
378- if (1 !== \preg_match ($ pattern , $ name )) {
379- throw new \InvalidArgumentException ("The command name ' $ name' is must match: $ pattern " );
380- }
381-
382- if ($ this ->isInternalCommand ($ name )) {
383- throw new \InvalidArgumentException ("The command name ' $ name' is not allowed. It is a built in command. " );
384- }
385- }
386-
387347 /**
388348 * @param string $name
389349 * @param string|array $aliases
390350 * @return $this
391351 */
392- public function addCommandAliases (string $ name , $ aliases ): self
352+ public function addAliases (string $ name , $ aliases ): self
393353 {
394- if (!$ name || !$ aliases ) {
395- return $ this ;
396- }
397-
398- foreach ((array )$ aliases as $ alias ) {
399- if ($ alias = trim ($ alias )) {
400- $ this ->commandAliases [$ alias ] = $ name ;
401- }
354+ if ($ name && $ aliases ) {
355+ $ this ->router ->setAlias ($ name , $ aliases );
402356 }
403357
404358 return $ this ;
405359 }
406360
407- /**
408- * @param string $name
409- * @return string
410- */
411- protected function getRealCommandName (string $ name ): string
412- {
413- return $ this ->commandAliases [$ name ] ?? $ name ;
414- }
415-
416- /**
417- * @param string $name
418- * @return mixed|null
419- */
420- public function findCommand (string $ name )
421- {
422- return $ this ->commands [$ name ] ?? $ this ->controllers [$ name ] ?? null ;
423- }
424-
425361 /**
426362 * @param int $level
427363 * @param string $format
@@ -440,86 +376,6 @@ public function logf(int $level, string $format, ...$args): void
440376 * getter/setter methods
441377 **********************************************************/
442378
443- /**
444- * @return array
445- */
446- public function getControllerNames (): array
447- {
448- return \array_keys ($ this ->controllers );
449- }
450-
451- /**
452- * @return array
453- */
454- public function getCommandNames (): array
455- {
456- return \array_keys ($ this ->commands );
457- }
458-
459- /**
460- * @param array $controllers
461- * @throws \InvalidArgumentException
462- */
463- public function setControllers (array $ controllers ): void
464- {
465- foreach ($ controllers as $ name => $ controller ) {
466- if (\is_int ($ name )) {
467- $ this ->controller ($ controller );
468- } else {
469- $ this ->controller ($ name , $ controller );
470- }
471- }
472- }
473-
474- /**
475- * @return array
476- */
477- public function getControllers (): array
478- {
479- return $ this ->controllers ;
480- }
481-
482- /**
483- * @param $name
484- * @return bool
485- */
486- public function isController (string $ name ): bool
487- {
488- return isset ($ this ->controllers [$ name ]);
489- }
490-
491- /**
492- * @param array $commands
493- * @throws \InvalidArgumentException
494- */
495- public function setCommands (array $ commands ): void
496- {
497- foreach ($ commands as $ name => $ handler ) {
498- if (\is_int ($ name )) {
499- $ this ->command ($ handler );
500- } else {
501- $ this ->command ($ name , $ handler );
502- }
503- }
504- }
505-
506- /**
507- * @return array
508- */
509- public function getCommands (): array
510- {
511- return $ this ->commands ;
512- }
513-
514- /**
515- * @param $name
516- * @return bool
517- */
518- public function isCommand (string $ name ): bool
519- {
520- return isset ($ this ->commands [$ name ]);
521- }
522-
523379 /**
524380 * @return string|null
525381 */
@@ -653,80 +509,6 @@ public function isProfile(): bool
653509 return (bool )$ this ->input ->getOpt ('profile ' , $ this ->getParam ('profile ' ));
654510 }
655511
656- /**
657- * @param null|string $name
658- * @return array
659- */
660- public function getCommandAliases (string $ name = null ): array
661- {
662- if (!$ name ) {
663- return $ this ->commandAliases ;
664- }
665-
666- return \array_keys ($ this ->commandAliases , $ name , true );
667- }
668-
669- /**
670- * @param array $commandAliases
671- */
672- public function setCommandAliases (array $ commandAliases ): void
673- {
674- $ this ->commandAliases = $ commandAliases ;
675- }
676-
677- /**
678- * @return array
679- */
680- public function getCommandsMeta (): array
681- {
682- return $ this ->commandsMeta ;
683- }
684-
685- /**
686- * @param string $command
687- * @param array $meta
688- */
689- public function setCommandMeta (string $ command , array $ meta ): void
690- {
691- if (isset ($ this ->commandsMeta [$ command ])) {
692- $ this ->commandsMeta [$ command ] = \array_merge ($ this ->commandsMeta [$ command ], $ meta );
693- } else {
694- $ this ->commandsMeta [$ command ] = $ meta ;
695- }
696- }
697-
698- /**
699- * @param string $command
700- * @return array
701- */
702- public function getCommandMeta (string $ command ): array
703- {
704- return $ this ->commandsMeta [$ command ] ?? [];
705- }
706-
707- /**
708- * @param string $command
709- * @param string $key
710- * @param $value
711- */
712- public function setCommandMetaValue (string $ command , string $ key , $ value ): void
713- {
714- if ($ value !== null ) {
715- $ this ->commandsMeta [$ command ][$ key ] = $ value ;
716- }
717- }
718-
719- /**
720- * @param string $command
721- * @param string $key
722- * @param mixed $default
723- * @return mixed
724- */
725- public function getCommandMetaValue (string $ command , string $ key , $ default = null )
726- {
727- return $ this ->commandsMeta [$ command ][$ key ] ?? $ default ;
728- }
729-
730512 /**
731513 * @return ErrorHandlerInterface
732514 */
0 commit comments