Skip to content

Commit ca8a820

Browse files
committed
rename some class, update some ...
1 parent 5d0e21f commit ca8a820

File tree

7 files changed

+32
-27
lines changed

7 files changed

+32
-27
lines changed

src/AbstractCommand.php renamed to src/AbstractHandler.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace Inhere\Console;
1010

11-
use Inhere\Console\Contract\BaseCommandInterface;
11+
use Inhere\Console\Contract\CommandHandlerInterface;
1212
use Inhere\Console\Contract\CommandInterface;
1313
use Inhere\Console\IO\Input;
1414
use Inhere\Console\IO\InputDefinition;
@@ -22,10 +22,10 @@
2222
use Toolkit\PhpUtil\PhpDoc;
2323

2424
/**
25-
* Class AbstractCommand
25+
* Class AbstractHandler
2626
* @package Inhere\Console
2727
*/
28-
abstract class AbstractCommand implements BaseCommandInterface
28+
abstract class AbstractHandler implements CommandHandlerInterface
2929
{
3030
use InputOutputAwareTrait, UserInteractAwareTrait;
3131

@@ -257,7 +257,7 @@ public function coroutineRun(): bool
257257
}
258258

259259
/**
260-
* before command execute
260+
* Before command execute
261261
* @return boolean It MUST return TRUE to continue execute.
262262
*/
263263
protected function beforeExecute(): bool
@@ -266,15 +266,15 @@ protected function beforeExecute(): bool
266266
}
267267

268268
/**
269-
* do execute command
269+
* Do execute command
270270
* @param Input $input
271271
* @param Output $output
272272
* @return int|mixed
273273
*/
274274
abstract protected function execute($input, $output);
275275

276276
/**
277-
* after command execute
277+
* After command execute
278278
*/
279279
protected function afterExecute(): void
280280
{
@@ -575,8 +575,7 @@ protected function showHelpByMethodAnnotations(string $method, string $action =
575575
}
576576

577577
$help['Global Options:'] = FormatUtil::alignOptions(
578-
\array_merge(Application::getGlobalOptions(),
579-
$this->commonOptions)
578+
\array_merge(Application::getGlobalOptions(), $this->commonOptions)
580579
);
581580
$this->output->mList($help, [
582581
'sepChar' => ' ',

src/Command.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,18 @@
2424
* }
2525
* ```
2626
*/
27-
abstract class Command extends AbstractCommand implements CommandInterface
27+
abstract class Command extends AbstractHandler implements CommandInterface
2828
{
2929
/*
30-
* do execute
31-
* @param \Inhere\Console\IO\Input $input
32-
* @param \Inhere\Console\IO\Output $output
33-
* @return int
30+
* Do execute command
3431
*/
3532
// protected function execute($input, $output)
3633
// {
3734
// // something logic ...
3835
// }
3936

4037
/*
41-
* configure
38+
* Configure command
4239
*/
4340
// protected function configure()
4441
// {
@@ -49,6 +46,7 @@ abstract class Command extends AbstractCommand implements CommandInterface
4946
// }
5047

5148
/**
49+
* Show help information
5250
* @return bool
5351
* @throws \ReflectionException
5452
*/

src/Contract/BaseCommandInterface.php renamed to src/Contract/CommandHandlerInterface.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
namespace Inhere\Console\Contract;
1010

1111
use Inhere\Console\AbstractApplication;
12+
use Inhere\Console\IO\Input;
1213
use Inhere\Console\IO\InputDefinition;
14+
use Inhere\Console\IO\Output;
1315

1416
/**
15-
* Interface BaseCommandInterface
17+
* Interface CommandHandlerInterface
1618
* @package Inhere\Console\Contract
1719
*/
18-
interface BaseCommandInterface
20+
interface CommandHandlerInterface
1921
{
2022
public const OK = 0;
2123
public const ERR = 2;
@@ -24,7 +26,7 @@ interface BaseCommandInterface
2426
public const ANNOTATION_VAR = '{%s}'; // '{$%s}';
2527

2628
/**
27-
* run command
29+
* Run command
2830
* @param string $command
2931
* @return int|mixed return int is exit code. other is command exec result.
3032
*/

src/Contract/CommandInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
* Interface CommandInterface
1313
* @package Inhere\Console\Contract
1414
*/
15-
interface CommandInterface extends BaseCommandInterface
15+
interface CommandInterface extends CommandHandlerInterface
1616
{
1717
}

src/Controller.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* Class Controller
2222
* @package Inhere\Console
2323
*/
24-
abstract class Controller extends AbstractCommand implements ControllerInterface
24+
abstract class Controller extends AbstractHandler implements ControllerInterface
2525
{
2626
/** @var array sub-command aliases */
2727
private static $commandAliases = [];
@@ -108,10 +108,11 @@ public function run(string $command = '')
108108
}
109109

110110
/**
111-
* load command configure
111+
* Load command configure
112112
*/
113113
protected function configure(): void
114114
{
115+
// eg. IndexConfigure() for indexCommand()
115116
$method = $this->action . 'Configure';
116117

117118
if (\method_exists($this, $method)) {
@@ -120,13 +121,14 @@ protected function configure(): void
120121
}
121122

122123
/**
123-
* 运行控制器的 action
124+
* Run command action in the group
125+
*
124126
* @param Input $input
125127
* @param Output $output
126128
* @return mixed
127129
* @throws \ReflectionException
128130
*/
129-
protected function execute($input, $output)
131+
final public function execute($input, $output)
130132
{
131133
$action = $this->action;
132134
$group = static::getName();
@@ -240,7 +242,7 @@ final public function showCommandList(): void
240242
$sName = \lcfirst(self::getName() ?: $ref->getShortName());
241243

242244
if (!($classDes = self::getDescription())) {
243-
$classDes = PhpDoc::description($ref->getDocComment()) ?: 'No description for the console controller';
245+
$classDes = PhpDoc::description($ref->getDocComment()) ?: 'No description for the command group';
244246
}
245247

246248
$commands = [];

src/Router.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,13 @@ protected function validateName(string $name): void
302302
}
303303
}
304304

305-
public function each(callable $fn)
305+
/**
306+
* @param callable $grpFunc
307+
* @param callable $cmdFunc
308+
*/
309+
public function sortedEach(callable $grpFunc, callable $cmdFunc): void
306310
{
307-
311+
// todo ...
308312
}
309313

310314
/**********************************************************

src/Traits/ApplicationHelpTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function showCommandList(): void
138138
foreach ($groups as $name => $info) {
139139
$options = $info['options'];
140140
$controller = $info['handler'];
141-
/** @var \Inhere\Console\AbstractCommand $controller */
141+
/** @var \Inhere\Console\AbstractHandler $controller */
142142
$desc = $controller::getDescription() ?: $placeholder;
143143
$aliases = $options['aliases'];
144144
$extra = $aliases ? ColorTag::wrap(
@@ -159,7 +159,7 @@ public function showCommandList(): void
159159
$options = $info['options'];
160160
$command = $info['handler'];
161161

162-
/** @var \Inhere\Console\AbstractCommand $command */
162+
/** @var \Inhere\Console\AbstractHandler $command */
163163
if (\is_subclass_of($command, CommandInterface::class)) {
164164
$desc = $command::getDescription() ?: $placeholder;
165165
} elseif ($msg = $options['description'] ?? '') {

0 commit comments

Comments
 (0)