Skip to content

Commit c913803

Browse files
committed
refactor: move some trait class to Decorate dir
1 parent ef50e5c commit c913803

18 files changed

+44
-70
lines changed

src/AbstractApplication.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
use Inhere\Console\Component\ErrorHandler;
1414
use Inhere\Console\Component\Router;
1515
use Inhere\Console\Component\Formatter\Title;
16-
use Inhere\Console\Concern\ApplicationHelpTrait;
1716
use Inhere\Console\Concern\InputOutputAwareTrait;
1817
use Inhere\Console\Concern\SimpleEventAwareTrait;
19-
use Inhere\Console\Concern\StyledOutputAwareTrait;
2018
use Inhere\Console\Contract\ApplicationInterface;
2119
use Inhere\Console\Contract\ErrorHandlerInterface;
20+
use Inhere\Console\Decorate\ApplicationHelpTrait;
21+
use Inhere\Console\Decorate\StyledOutputAwareTrait;
2222
use Inhere\Console\IO\Input;
2323
use Inhere\Console\IO\Output;
2424
use Inhere\Console\Util\Helper;

src/Application.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use RuntimeException;
2121
use Throwable;
2222
use Toolkit\FsUtil\Dir;
23+
use Toolkit\PFlag\FlagsParser;
2324
use Toolkit\PFlag\SFlags;
2425
use Toolkit\Stdlib\Helper\Assert;
2526
use Toolkit\Stdlib\Helper\DataHelper;
@@ -121,7 +122,7 @@ public function addControllers(array $controllers): void
121122

122123
/**
123124
* @param string $name
124-
* @param class-string|CommandInterface|null|Closure():void $handler
125+
* @param class-string|CommandInterface|null|Closure(FlagsParser, Output):void $handler
125126
* @param array{desc: string, aliases: array, options: array, arguments: array} $config config the command.
126127
*
127128
* @return Application
@@ -138,7 +139,7 @@ public function command(string $name, string|Closure|CommandInterface $handler =
138139
* add command
139140
*
140141
* @param string $name
141-
* @param class-string|CommandInterface|null|Closure():void $handler
142+
* @param class-string|CommandInterface|null|Closure(FlagsParser, Output):void $handler
142143
* @param array{desc: string, aliases: array, options: array, arguments: array} $config config the command.
143144
*
144145
* @return Application

src/Concern/AdvancedFormatOutputTrait.php

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/Controller.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
namespace Inhere\Console;
1111

1212
use Generator;
13-
use Inhere\Console\Concern\ControllerHelpTrait;
1413
use Inhere\Console\Contract\ControllerInterface;
14+
use Inhere\Console\Decorate\ControllerHelpTrait;
1515
use Inhere\Console\Exception\ConsoleException;
1616
use Inhere\Console\Handler\AbstractHandler;
1717
use Inhere\Console\IO\Input;
@@ -255,7 +255,7 @@ protected function beforeRun(): void
255255
/**
256256
* @param array $args
257257
*
258-
* @return int|mixed
258+
* @return mixed
259259
* @throws Throwable
260260
*/
261261
public function doRun(array $args): mixed

src/Concern/ApplicationHelpTrait.php renamed to src/Decorate/ApplicationHelpTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @license https://github.com/inhere/php-console/blob/master/LICENSE
88
*/
99

10-
namespace Inhere\Console\Concern;
10+
namespace Inhere\Console\Decorate;
1111

1212
use Inhere\Console\Handler\AbstractHandler;
1313
use Inhere\Console\Console;
@@ -43,7 +43,7 @@
4343
/**
4444
* Trait ApplicationHelpTrait
4545
*
46-
* @package Inhere\Console\Concern
46+
* @package Inhere\Console\Decorate
4747
*/
4848
trait ApplicationHelpTrait
4949
{

src/Concern/CommandHelpTrait.php renamed to src/Decorate/CommandHelpTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @license https://github.com/inhere/php-console/blob/master/LICENSE
88
*/
99

10-
namespace Inhere\Console\Concern;
10+
namespace Inhere\Console\Decorate;
1111

1212
use Inhere\Console\Handler\AbstractHandler;
1313
use Inhere\Console\Console;
@@ -21,7 +21,7 @@
2121
/**
2222
* Trait CommandHelpTrait
2323
*
24-
* @package Inhere\Console\Concern
24+
* @package Inhere\Console\Decorate
2525
*/
2626
trait CommandHelpTrait
2727
{

src/Concern/ControllerHelpTrait.php renamed to src/Decorate/ControllerHelpTrait.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @license https://github.com/inhere/php-console/blob/master/LICENSE
88
*/
99

10-
namespace Inhere\Console\Concern;
10+
namespace Inhere\Console\Decorate;
1111

1212
use Inhere\Console\Console;
1313
use Inhere\Console\GlobalOption;
@@ -27,7 +27,7 @@
2727
/**
2828
* Trait ControllerHelpTrait
2929
*
30-
* @package Inhere\Console\Concern
30+
* @package Inhere\Console\Decorate
3131
*/
3232
trait ControllerHelpTrait
3333
{
@@ -91,15 +91,15 @@ protected function beforeShowCommandList(): void
9191
*/
9292
public function showCommandList(): void
9393
{
94-
$this->logf(Console::VERB_DEBUG, 'display all sub-commands list of the group: %s', static::$name);
95-
94+
$name = self::getName();
95+
$this->logf(Console::VERB_DEBUG, 'display all sub-commands list of the group: %s', $name);
9696
$this->beforeShowCommandList();
9797

98-
$ref = new ReflectionClass($this);
99-
$sName = self::getName() ?: lcfirst($ref->getShortName());
98+
$refCls = new ReflectionClass($this);
99+
$sName = $name ?: lcfirst($refCls->getShortName());
100100

101101
if (!($classDes = self::getDesc())) {
102-
$classDes = PhpDoc::description($ref->getDocComment()) ?: 'No description for the command group';
102+
$classDes = PhpDoc::description($refCls->getDocComment()) ?: 'No description for the command group';
103103
}
104104

105105
$commands = [];
@@ -109,7 +109,7 @@ public function showCommandList(): void
109109
/**
110110
* @var $cmd string The command name.
111111
*/
112-
foreach ($this->getAllCommandMethods($ref) as $cmd => $m) {
112+
foreach ($this->getAllCommandMethods($refCls) as $cmd => $m) {
113113
if (!$cmd) {
114114
continue;
115115
}

src/Concern/FormatOutputAwareTrait.php renamed to src/Decorate/FormatOutputAwareTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @license https://github.com/inhere/php-console/blob/master/LICENSE
88
*/
99

10-
namespace Inhere\Console\Concern;
10+
namespace Inhere\Console\Decorate;
1111

1212
use Inhere\Console\Component\Formatter\JSONPretty;
1313
use Inhere\Console\Console;
@@ -21,7 +21,7 @@
2121
/**
2222
* Class FormatOutputAwareTrait
2323
*
24-
* @package Inhere\Console\Traits
24+
* @package Inhere\Console\Decorate
2525
*/
2626
trait FormatOutputAwareTrait
2727
{

src/Concern/RuntimeProfileTrait.php renamed to src/Decorate/RuntimeProfileTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @license https://github.com/inhere/php-console/blob/master/LICENSE
88
*/
99

10-
namespace Inhere\Console\Concern;
10+
namespace Inhere\Console\Decorate;
1111

1212
use InvalidArgumentException;
1313
use Toolkit\Stdlib\Helper\PhpHelper;
@@ -20,7 +20,7 @@
2020
/**
2121
* Trait RuntimeProfileTrait
2222
*
23-
* @package Inhere\Library\Concern
23+
* @package Inhere\Console\Decorate
2424
*/
2525
trait RuntimeProfileTrait
2626
{

src/Concern/StyledOutputAwareTrait.php renamed to src/Decorate/StyledOutputAwareTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @license https://github.com/inhere/php-console/blob/master/LICENSE
88
*/
99

10-
namespace Inhere\Console\Concern;
10+
namespace Inhere\Console\Decorate;
1111

1212
use Closure;
1313
use Generator;
@@ -29,7 +29,7 @@
2929
/**
3030
* Trait StyledOutputAwareTrait
3131
*
32-
* @package Inhere\Console\Concern
32+
* @package Inhere\Console\Decorate
3333
*
3434
* @method int info($messages, $quit = false)
3535
* @method int note($messages, $quit = false)

0 commit comments

Comments
 (0)