|
|
@ -8,7 +8,7 @@ use Symfony\Component\Console\Command\Command;
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* A manager of commands auto prefix base on class namespace
|
|
|
|
* A manager of commands auto prefix base on class namespace
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
class AutoPrefixManager implements IAutoPrefixManager {
|
|
|
|
class AutoPrefixNamespaceManager implements IAutoPrefixManager {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @var string The base namespace
|
|
|
|
* @var string The base namespace
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -45,6 +45,9 @@ class AutoPrefixManager implements IAutoPrefixManager {
|
|
|
|
* @return $this
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function setNamespace (string $namespace): self {
|
|
|
|
public function setNamespace (string $namespace): self {
|
|
|
|
|
|
|
|
if (mb_substr($namespace, 0, 1) !== '\\') {
|
|
|
|
|
|
|
|
$namespace = '\\' . $namespace;
|
|
|
|
|
|
|
|
}
|
|
|
|
$this->namespace = $namespace;
|
|
|
|
$this->namespace = $namespace;
|
|
|
|
return $this;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -74,16 +77,21 @@ class AutoPrefixManager implements IAutoPrefixManager {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function getCommandPrefix (Command $command): ?string {
|
|
|
|
public function getCommandPrefix (Command $command): ?string {
|
|
|
|
$commandClass = new ReflectionClass($command);
|
|
|
|
$commandClass = new ReflectionClass($command);
|
|
|
|
$commandNamespace = $commandClass->getNamespaceName();
|
|
|
|
$commandNamespace = '\\' . $commandClass->getNamespaceName();
|
|
|
|
|
|
|
|
|
|
|
|
if ($commandNamespace !== $this->getNamespace() && mb_substr($commandNamespace, mb_strlen($this->getNamespace() . '\\')) !== $this->getNamespace() . '\\') {
|
|
|
|
if ($commandNamespace !== $this->getNamespace() && mb_substr($commandNamespace, mb_strlen($this->getNamespace() . '\\')) !== $this->getNamespace() . '\\') {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (mb_strlen($this->getInitialPrefix()) > 0 ? $this->getInitialPrefix() . ':' : '') . mb_strtolower(
|
|
|
|
return implode(
|
|
|
|
str_replace(
|
|
|
|
':',
|
|
|
|
|
|
|
|
array_filter(
|
|
|
|
[
|
|
|
|
[
|
|
|
|
$this->getNamespace() . '\\',
|
|
|
|
$this->getInitialPrefix(),
|
|
|
|
'\\',
|
|
|
|
mb_strtolower(
|
|
|
|
|
|
|
|
preg_replace(
|
|
|
|
|
|
|
|
[
|
|
|
|
|
|
|
|
'/^' . preg_quote($this->getNamespace(), '/') . '(?:\\\\|$)/',
|
|
|
|
|
|
|
|
'/\\\\/',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'',
|
|
|
|
'',
|
|
|
@ -91,6 +99,9 @@ class AutoPrefixManager implements IAutoPrefixManager {
|
|
|
|
],
|
|
|
|
],
|
|
|
|
$commandNamespace
|
|
|
|
$commandNamespace
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
)
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|