Skip to content

Commit 4809e12

Browse files
committed
update: add more param type difine. some update...
1 parent fbaabed commit 4809e12

File tree

8 files changed

+30
-28
lines changed

8 files changed

+30
-28
lines changed
File renamed without changes.

examples/home

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require dirname(__DIR__) . '/test/boot.php';
1212

1313
$in = new \Inhere\Console\IO\Input();
1414
$ctrl = new HomeController($in, new \Inhere\Console\IO\Output());
15-
$ctrl->setStandAlone();
15+
$ctrl->setExecutionAlone();
1616

1717
try {
1818
exit($ctrl->run($in->getCommand()));

src/Application.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function controllers(array $controllers)
104104
* @param string|Command $name
105105
* @param string|\Closure|Command $handler
106106
* @param null|array|string $option
107-
* @return $this
107+
* @return $this|mixed
108108
* @throws \InvalidArgumentException
109109
*/
110110
public function command(string $name, $handler = null, $option = null)
@@ -393,7 +393,7 @@ public function runAction($name, $action, $believable = false, $standAlone = fal
393393
$object::setName($name);
394394
$object->setApp($this);
395395
$object->setDelimiter($this->delimiter);
396-
$object->setStandAlone($standAlone);
396+
$object->setExecutionAlone($standAlone);
397397

398398
return $object->run($action);
399399
}

src/Base/AbstractCommand.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,10 @@ protected function showHelp(): bool
261261

262262
/**
263263
* prepare run
264+
* @throws \InvalidArgumentException
264265
* @throws \RuntimeException
265266
*/
266-
protected function prepare()
267+
protected function prepare(): bool
267268
{
268269
if ($this->processTitle) {
269270
if (\function_exists('cli_set_process_title')) {
@@ -285,6 +286,7 @@ protected function prepare()
285286
/**
286287
* validate input arguments and options
287288
* @return bool
289+
* @throws \InvalidArgumentException
288290
*/
289291
public function validateInput(): bool
290292
{
@@ -398,11 +400,11 @@ protected function addAnnotationVars(array $map)
398400

399401
/**
400402
* @param string $name
401-
* @param string $value
403+
* @param string|array $value
402404
*/
403405
protected function setAnnotationVar(string $name, $value)
404406
{
405-
$this->annotationVars[$name] = (string)$value;
407+
$this->annotationVars[$name] = \is_array($value) ? \implode(',', $value) : (string)$value;
406408
}
407409

408410
/**

src/Base/ApplicationInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function controller(string $name, string $class = null, $option = null);
6969
* array:
7070
* - aliases The command aliases
7171
* - description The description message
72-
* @return $this
72+
* @return mixed
7373
* @throws \InvalidArgumentException
7474
*/
7575
public function command(string $name, $handler = null, $option = null);

src/Controller.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ abstract class Controller extends AbstractCommand implements ControllerInterface
3636
/** @var string */
3737
private $delimiter = ':'; // '/' ':'
3838

39-
/** @var bool */
40-
private $standAlone = false;
39+
/** @var bool Execution alone */
40+
private $executionAlone = false;
4141

4242
/** @var string */
4343
private $defaultAction = 'help';
@@ -228,7 +228,7 @@ protected function beforeShowCommandList()
228228
{
229229
// do something ...
230230
}
231-
231+
232232
/**
233233
* show command list of the controller class
234234
* @throws \ReflectionException
@@ -284,7 +284,7 @@ final public function showCommandList()
284284

285285
$script = $this->getScriptName();
286286

287-
if ($this->standAlone) {
287+
if ($this->executionAlone) {
288288
$name = $sName . ' ';
289289
$usage = "$script <info>{command}</info> [arguments ...] [options ...]";
290290
} else {
@@ -305,7 +305,7 @@ final public function showCommandList()
305305

306306
$this->write(sprintf(
307307
"More information about a command, please use: <cyan>$script $name{command} -h</cyan>",
308-
$this->standAlone ? ' ' . $name : ''
308+
$this->executionAlone ? ' ' . $name : ''
309309
));
310310
$this->output->flush();
311311
}
@@ -403,7 +403,7 @@ public function getAction(): string
403403
* @param string $action
404404
* @return $this
405405
*/
406-
public function setAction(string $action)
406+
public function setAction(string $action): self
407407
{
408408
if ($action) {
409409
$this->action = FormatUtil::camelCase($action);
@@ -463,17 +463,17 @@ public function setNotFoundCallback(string $notFoundCallback)
463463
/**
464464
* @return bool
465465
*/
466-
public function isStandAlone(): bool
466+
public function isExecutionAlone(): bool
467467
{
468-
return $this->standAlone;
468+
return $this->executionAlone;
469469
}
470470

471471
/**
472-
* @param bool $standAlone
472+
* @param bool $executionAlone
473473
*/
474-
public function setStandAlone($standAlone = true)
474+
public function setExecutionAlone($executionAlone = true)
475475
{
476-
$this->standAlone = (bool)$standAlone;
476+
$this->executionAlone = (bool)$executionAlone;
477477
}
478478

479479
/**

src/LiteApp.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class LiteApp
5353
/**
5454
* @param bool $exit
5555
*/
56-
public function run($exit = true)
56+
public function run(bool $exit = true)
5757
{
5858
$this->parseCliArgv();
5959

@@ -68,7 +68,7 @@ public function run($exit = true)
6868
/**
6969
* @param bool $exit
7070
*/
71-
public function dispatch($exit = true)
71+
public function dispatch(bool $exit = true)
7272
{
7373
if (!$command = $this->command) {
7474
$this->showCommands();
@@ -100,12 +100,12 @@ public function stop($code = 0)
100100
}
101101

102102
/**
103-
* @param $command
103+
* @param string $command
104104
* @param $handler
105105
* @return mixed
106106
* @throws \InvalidArgumentException
107107
*/
108-
public function runHandler($command, $handler)
108+
public function runHandler(string $command, $handler)
109109
{
110110
if (\is_string($handler)) {
111111
// function name
@@ -192,7 +192,7 @@ public function parseCliArgv()
192192
* @param string $description
193193
* @throws \InvalidArgumentException
194194
*/
195-
public function addCommand($command, $handler, $description = '')
195+
public function addCommand(string $command, $handler, $description = '')
196196
{
197197
if (!$command || !$handler) {
198198
throw new \InvalidArgumentException('Invalid arguments');

src/Utils/Annotation.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ final class Annotation
2424
* @param array $ignored
2525
* @return array The parsed tags
2626
*/
27-
public static function getTags($comment, array $ignored = ['param', 'return']): array
27+
public static function getTags(string $comment, array $ignored = ['param', 'return']): array
2828
{
2929
$comment = str_replace("\r\n", "\n", trim($comment, "/ \n"));
3030
$comment = "@description \n" . str_replace("\r", '',
@@ -57,10 +57,10 @@ public static function getTags($comment, array $ignored = ['param', 'return']):
5757
/**
5858
* Returns the first line of docBlock.
5959
*
60-
* @param $comment
60+
* @param string $comment
6161
* @return string
6262
*/
63-
public static function firstLine($comment): string
63+
public static function firstLine(string $comment): string
6464
{
6565
$docLines = preg_split('~\R~u', $comment);
6666

@@ -75,10 +75,10 @@ public static function firstLine($comment): string
7575
* Returns full description from the doc-block.
7676
* If have multi line text, will return multi line.
7777
*
78-
* @param $comment
78+
* @param string $comment
7979
* @return string
8080
*/
81-
public static function description($comment): string
81+
public static function description(string $comment): string
8282
{
8383
$comment = str_replace("\r", '', trim(preg_replace('/^\s*\**( |\t)?/m', '', trim($comment, '/'))));
8484

0 commit comments

Comments
 (0)