Skip to content

Commit

Permalink
refactor: move some trait class to Decorate dir
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Dec 25, 2021
1 parent ef50e5c commit c913803
Show file tree
Hide file tree
Showing 18 changed files with 44 additions and 70 deletions.
4 changes: 2 additions & 2 deletions src/AbstractApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
use Inhere\Console\Component\ErrorHandler;
use Inhere\Console\Component\Router;
use Inhere\Console\Component\Formatter\Title;
use Inhere\Console\Concern\ApplicationHelpTrait;
use Inhere\Console\Concern\InputOutputAwareTrait;
use Inhere\Console\Concern\SimpleEventAwareTrait;
use Inhere\Console\Concern\StyledOutputAwareTrait;
use Inhere\Console\Contract\ApplicationInterface;
use Inhere\Console\Contract\ErrorHandlerInterface;
use Inhere\Console\Decorate\ApplicationHelpTrait;
use Inhere\Console\Decorate\StyledOutputAwareTrait;
use Inhere\Console\IO\Input;
use Inhere\Console\IO\Output;
use Inhere\Console\Util\Helper;
Expand Down
5 changes: 3 additions & 2 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use RuntimeException;
use Throwable;
use Toolkit\FsUtil\Dir;
use Toolkit\PFlag\FlagsParser;
use Toolkit\PFlag\SFlags;
use Toolkit\Stdlib\Helper\Assert;
use Toolkit\Stdlib\Helper\DataHelper;
Expand Down Expand Up @@ -121,7 +122,7 @@ public function addControllers(array $controllers): void

/**
* @param string $name
* @param class-string|CommandInterface|null|Closure():void $handler
* @param class-string|CommandInterface|null|Closure(FlagsParser, Output):void $handler
* @param array{desc: string, aliases: array, options: array, arguments: array} $config config the command.
*
* @return Application
Expand All @@ -138,7 +139,7 @@ public function command(string $name, string|Closure|CommandInterface $handler =
* add command
*
* @param string $name
* @param class-string|CommandInterface|null|Closure():void $handler
* @param class-string|CommandInterface|null|Closure(FlagsParser, Output):void $handler
* @param array{desc: string, aliases: array, options: array, arguments: array} $config config the command.
*
* @return Application
Expand Down
19 changes: 0 additions & 19 deletions src/Concern/AdvancedFormatOutputTrait.php

This file was deleted.

4 changes: 2 additions & 2 deletions src/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
namespace Inhere\Console;

use Generator;
use Inhere\Console\Concern\ControllerHelpTrait;
use Inhere\Console\Contract\ControllerInterface;
use Inhere\Console\Decorate\ControllerHelpTrait;
use Inhere\Console\Exception\ConsoleException;
use Inhere\Console\Handler\AbstractHandler;
use Inhere\Console\IO\Input;
Expand Down Expand Up @@ -255,7 +255,7 @@ protected function beforeRun(): void
/**
* @param array $args
*
* @return int|mixed
* @return mixed
* @throws Throwable
*/
public function doRun(array $args): mixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @license https://github.com/inhere/php-console/blob/master/LICENSE
*/

namespace Inhere\Console\Concern;
namespace Inhere\Console\Decorate;

use Inhere\Console\Handler\AbstractHandler;
use Inhere\Console\Console;
Expand Down Expand Up @@ -43,7 +43,7 @@
/**
* Trait ApplicationHelpTrait
*
* @package Inhere\Console\Concern
* @package Inhere\Console\Decorate
*/
trait ApplicationHelpTrait
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @license https://github.com/inhere/php-console/blob/master/LICENSE
*/

namespace Inhere\Console\Concern;
namespace Inhere\Console\Decorate;

use Inhere\Console\Handler\AbstractHandler;
use Inhere\Console\Console;
Expand All @@ -21,7 +21,7 @@
/**
* Trait CommandHelpTrait
*
* @package Inhere\Console\Concern
* @package Inhere\Console\Decorate
*/
trait CommandHelpTrait
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @license https://github.com/inhere/php-console/blob/master/LICENSE
*/

namespace Inhere\Console\Concern;
namespace Inhere\Console\Decorate;

use Inhere\Console\Console;
use Inhere\Console\GlobalOption;
Expand All @@ -27,7 +27,7 @@
/**
* Trait ControllerHelpTrait
*
* @package Inhere\Console\Concern
* @package Inhere\Console\Decorate
*/
trait ControllerHelpTrait
{
Expand Down Expand Up @@ -91,15 +91,15 @@ protected function beforeShowCommandList(): void
*/
public function showCommandList(): void
{
$this->logf(Console::VERB_DEBUG, 'display all sub-commands list of the group: %s', static::$name);

$name = self::getName();
$this->logf(Console::VERB_DEBUG, 'display all sub-commands list of the group: %s', $name);
$this->beforeShowCommandList();

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

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

$commands = [];
Expand All @@ -109,7 +109,7 @@ public function showCommandList(): void
/**
* @var $cmd string The command name.
*/
foreach ($this->getAllCommandMethods($ref) as $cmd => $m) {
foreach ($this->getAllCommandMethods($refCls) as $cmd => $m) {
if (!$cmd) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @license https://github.com/inhere/php-console/blob/master/LICENSE
*/

namespace Inhere\Console\Concern;
namespace Inhere\Console\Decorate;

use Inhere\Console\Component\Formatter\JSONPretty;
use Inhere\Console\Console;
Expand All @@ -21,7 +21,7 @@
/**
* Class FormatOutputAwareTrait
*
* @package Inhere\Console\Traits
* @package Inhere\Console\Decorate
*/
trait FormatOutputAwareTrait
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @license https://github.com/inhere/php-console/blob/master/LICENSE
*/

namespace Inhere\Console\Concern;
namespace Inhere\Console\Decorate;

use InvalidArgumentException;
use Toolkit\Stdlib\Helper\PhpHelper;
Expand All @@ -20,7 +20,7 @@
/**
* Trait RuntimeProfileTrait
*
* @package Inhere\Library\Concern
* @package Inhere\Console\Decorate
*/
trait RuntimeProfileTrait
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @license https://github.com/inhere/php-console/blob/master/LICENSE
*/

namespace Inhere\Console\Concern;
namespace Inhere\Console\Decorate;

use Closure;
use Generator;
Expand All @@ -29,7 +29,7 @@
/**
* Trait StyledOutputAwareTrait
*
* @package Inhere\Console\Concern
* @package Inhere\Console\Decorate
*
* @method int info($messages, $quit = false)
* @method int note($messages, $quit = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @license https://github.com/inhere/php-console/blob/master/LICENSE
*/

namespace Inhere\Console\Concern;
namespace Inhere\Console\Decorate;

use Closure;
use Inhere\Console\Command;
Expand All @@ -30,7 +30,7 @@
/**
* Trait SubCommandsWareTrait
*
* @package Inhere\Console\Concern
* @package Inhere\Console\Decorate
*/
trait SubCommandsWareTrait
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @license https://github.com/inhere/php-console/blob/master/LICENSE
*/

namespace Inhere\Console\Concern;
namespace Inhere\Console\Decorate;

use Closure;
use Inhere\Console\Util\Interact;
Expand All @@ -17,7 +17,7 @@
/**
* Class UserInteractAwareTrait
*
* @package Inhere\Console\Concern
* @package Inhere\Console\Decorate
* @see Interact
*
* @method string readRow($message = null, $nl = false)
Expand Down
17 changes: 9 additions & 8 deletions src/Handler/AbstractHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
use Inhere\Console\Annotate\DocblockRules;
use Inhere\Console\Component\ErrorHandler;
use Inhere\Console\Concern\AttachApplicationTrait;
use Inhere\Console\Concern\CommandHelpTrait;
use Inhere\Console\Concern\InputOutputAwareTrait;
use Inhere\Console\Concern\SubCommandsWareTrait;
use Inhere\Console\Concern\UserInteractAwareTrait;
use Inhere\Console\Decorate\UserInteractAwareTrait;
use Inhere\Console\Console;
use Inhere\Console\ConsoleEvent;
use Inhere\Console\Contract\CommandHandlerInterface;
use Inhere\Console\Contract\CommandInterface;
use Inhere\Console\Decorate\CommandHelpTrait;
use Inhere\Console\Decorate\SubCommandsWareTrait;
use Inhere\Console\IO\Input;
use Inhere\Console\IO\Output;
use Inhere\Console\Util\Helper;
Expand Down Expand Up @@ -54,22 +54,23 @@ abstract class AbstractHandler implements CommandHandlerInterface
use SubCommandsWareTrait;

/**
* group/command name e.g 'test' 'test:one'
* The group/command name e.g 'test' 'test:one'
*
* @var string
*/
protected static string $name = '';

/**
* command/controller description message
* please use the property setting current controller/command description
* The command/controller description message.
*
* TIP: please use the property setting current controller/command description
*
* @var string
*/
protected static string $desc = '';

/**
* command/controller description message
* The command/controller description message
*
* @var string
* @deprecated please use {@see $desc}
Expand Down Expand Up @@ -327,7 +328,7 @@ public function run(array $args): mixed
*
* @param array $args
*
* @return int|mixed
* @return mixed
*/
protected function doRun(array $args): mixed
{
Expand Down
2 changes: 1 addition & 1 deletion src/IO/Output.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Inhere\Console\IO;

use Inhere\Console\Concern\FormatOutputAwareTrait;
use Inhere\Console\Decorate\FormatOutputAwareTrait;
use Inhere\Console\Console;
use Inhere\Console\IO\Output\StreamOutput;
use Toolkit\Cli\Cli;
Expand Down
12 changes: 1 addition & 11 deletions src/Util/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace Inhere\Console\Util;

use FilesystemIterator;
use Inhere\Console\Concern\RuntimeProfileTrait;
use Inhere\Console\Decorate\RuntimeProfileTrait;
use Inhere\Console\ConsoleConst;
use InvalidArgumentException;
use RecursiveCallbackFilterIterator;
Expand Down Expand Up @@ -69,16 +69,6 @@ public static function hasMode(int $haystack, int $value): bool
return ($haystack & $value) > 0;
}

/**
* @param string $path
*
* @return bool
*/
public static function isAbsPath(string $path): bool
{
return str_starts_with($path, '/') || 1 === preg_match('#^[a-z]:[\/|\\\]{1}.+#i', $path);
}

/**
* @param string $name
*/
Expand Down
3 changes: 2 additions & 1 deletion src/Util/PhpDevServe.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Exception;
use RuntimeException;
use Toolkit\Cli\Cli;
use Toolkit\FsUtil\Path;
use Toolkit\Stdlib\Json;
use Toolkit\Sys\Sys;
use function explode;
Expand Down Expand Up @@ -189,7 +190,7 @@ protected function printDefaultMessage(): void
$docRoot = $workDir;
if ($this->docRoot) {
$docRoot = $this->docRoot;
$docRoot = Helper::isAbsPath($docRoot) ? $docRoot : $workDir . '/' . $docRoot;
$docRoot = Path::isAbsPath($docRoot) ? $docRoot : $workDir . '/' . $docRoot;
}

Cli::writeln([
Expand Down
2 changes: 1 addition & 1 deletion test/TestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TestCommand extends Command
{
protected static string $name = 'test1';

protected static string $description = 'command description message';
protected static string $desc = 'command description message';

/**
* do execute command
Expand Down
2 changes: 1 addition & 1 deletion test/TestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TestController extends Controller
{
protected static string $name = 'test';

protected static string $description = 'controller description message';
protected static string $desc = 'controller description message';

/**
* this is an demo command in test
Expand Down

0 comments on commit c913803

Please sign in to comment.