Skip to content

Commit

Permalink
remove invalid property
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jan 1, 2019
1 parent 4e959fc commit 3512f78
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 54 deletions.
45 changes: 9 additions & 36 deletions src/AbstractApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ abstract class AbstractApplication implements ApplicationInterface
'profile' => false,
'version' => '0.5.1',
'publishAt' => '2017.03.24',
'updateAt' => '2017.03.24',
'updateAt' => '2019.01.01',
'rootPath' => '',
'hideRootPath' => true,

// 'timeZone' => 'Asia/Shanghai',
// 'env' => 'pdt', // dev test pdt
// 'env' => 'prod', // dev test prod
// 'charset' => 'UTF-8',

'logoText' => '',
Expand All @@ -74,15 +74,12 @@ abstract class AbstractApplication implements ApplicationInterface
/** @var string Command delimiter. e.g dev:serve */
public $delimiter = ':'; // '/' ':'

/** @var string Current command name */
private $commandName;

/** @var array Some metadata for command */
/**
* @var array Some metadata for command
* - description
*/
private $commandsMeta = [];

/** @var array Some message for command */
private $commandMessages = [];

/** @var array Save command aliases */
private $commandAliases = [];

Expand Down Expand Up @@ -126,8 +123,6 @@ protected function init()
'endMemory' => 0,
];

$this->commandName = $this->input->getCommand();

$this->registerErrorHandle();
}

Expand Down Expand Up @@ -504,30 +499,6 @@ public function showCommandList($quit = true)
$quit && $this->stop();
}

/**
* @param string $name
* @param string $default
* @return string|null
*/
public function getCommandMessage(string $name, $default = null)
{
return $this->commandMessages[$name] ?? $default;
}

/**
* @param string $name The command name
* @param string $message
* @return $this
*/
public function addCommandMessage($name, $message): self
{
if ($name && $message) {
$this->commandMessages[$name] = $message;
}

return $this;
}

/**
* @param string $name
* @param string|array $aliases
Expand Down Expand Up @@ -834,7 +805,9 @@ public function getCommandMeta(string $command): array
*/
public function setCommandMetaValue(string $command, string $key, $value)
{
$this->commandsMeta[$command][$key] = $value;
if ($value !== null) {
$this->commandsMeta[$command][$key] = $value;
}
}

/**
Expand Down
29 changes: 11 additions & 18 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ class Application extends AbstractApplication
****************************************************************************/

/**
* Register a app group command(by controller)
* @param string $name The controller name
* @param string|Controller $class The controller class
* @param null|array|string $option
* @return static
* @throws \InvalidArgumentException
* {@inheritdoc}
*/
public function controller(string $name, $class = null, $option = null)
{
Expand Down Expand Up @@ -69,10 +64,11 @@ public function controller(string $name, $class = null, $option = null)
// has option information
if ($option) {
if (\is_string($option)) {
$this->addCommandMessage($name, $option);
$this->setCommandMetaValue($name, 'description', $option);
} elseif (\is_array($option)) {
$this->addCommandAliases($name, $option['aliases'] ?? null);
$this->addCommandMessage($name, $option['description'] ?? null);
unset($option['aliases']);
$this->setCommandMeta($name, $option);
}
}

Expand All @@ -99,12 +95,7 @@ public function controllers(array $controllers)
}

/**
* Register a app independent console command
* @param string|Command $name
* @param string|\Closure|Command $handler
* @param null|array|string $option
* @return $this|mixed
* @throws \InvalidArgumentException
* {@inheritdoc}
*/
public function command(string $name, $handler = null, $option = null)
{
Expand Down Expand Up @@ -139,17 +130,18 @@ public function command(string $name, $handler = null, $option = null)
return $this;
}

// allow define aliases in Command class by Command::aliases()
if ($aliases = $handler::aliases()) {
$option['aliases'] = isset($option['aliases']) ? \array_merge($option['aliases'], $aliases) : $aliases;
}
} elseif (!\is_object($handler) || !\method_exists($handler, '__invoke')) {
Helper::throwInvalidArgument(
'The console command handler must is an subclass of %s OR a Closure OR a object have method __invoke()',
Command::class
);
}

// allow define aliases in Command class by Command::aliases()
if ($aliases = $handler::aliases()) {
$option['aliases'] = isset($option['aliases']) ? \array_merge($option['aliases'], $aliases) : $aliases;
}

// is an class name string
$this->commands[$name] = $handler;

Expand All @@ -159,6 +151,7 @@ public function command(string $name, $handler = null, $option = null)
$this->setCommandMetaValue($name, 'description', $option);
} elseif (\is_array($option)) {
$this->addCommandAliases($name, $option['aliases'] ?? null);
unset($option['aliases']);
$this->setCommandMeta($name, $option);
}
}
Expand Down

0 comments on commit 3512f78

Please sign in to comment.