diff --git a/src/Cli/Console/Command.php b/src/Cli/Console/Command.php index c2672bf5..2fcf849a 100644 --- a/src/Cli/Console/Command.php +++ b/src/Cli/Console/Command.php @@ -19,6 +19,7 @@ use Ahc\Cli\Output\ProgressBar; use Ahc\Cli\Output\Writer; use BlitzPHP\Exceptions\CLIException; +use BlitzPHP\Utilities\String\Text; use Psr\Log\LoggerInterface; /** @@ -169,7 +170,7 @@ abstract class Command /** * Options recus apres executions */ - private array $_options = []; + protected array $_options = []; /** * @param Console $app Application Console @@ -224,7 +225,11 @@ final public function setArguments(array $arguments = []): self */ final public function argument(string $name, mixed $default = null): mixed { - return $this->_arguments[$name] ?? $default; + if (isset($this->_arguments[$name])) { + return $this->_arguments[$name]; + } + + return $this->_arguments[Text::camel($name)] ?? $default; } /** @@ -240,7 +245,11 @@ final public function getArg(string $name, mixed $default = null) */ final public function option(string $name, mixed $default = null): mixed { - return $this->_options[$name] ?? $default; + if (isset($this->_options[$name])) { + return $this->_options[$name]; + } + + return $this->_options[Text::camel($name)] ?? $default; } /** @@ -258,7 +267,11 @@ final public function param(string $name, mixed $default = null): mixed { $params = array_merge($this->_arguments, $this->_options); - return $params[$name] ?? $default; + if (isset($params[$name])) { + return $params[$name]; + } + + return $params[Text::camel($name)] ?? $default; } /** @@ -639,16 +652,8 @@ public function __isset(string $key): bool * * @return void */ - protected function initProps() + private function initProps() { - if (! is_cli()) { - if (! file_exists($ou = TEMP_PATH . 'blitz-cli.txt')) { - file_put_contents($ou, '', LOCK_EX); - } - - $this->app->io(new Interactor($ou, $ou)); - } - $this->io = $this->app->io(); $this->writer = $this->io->writer(); $this->reader = $this->io->reader(); diff --git a/src/Config/Config.php b/src/Config/Config.php index 4d761f23..46269092 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -154,8 +154,10 @@ public function reset(array|string|null $keys = null): void * Rend disponible un groupe de configuration qui n'existe pas (pas de fichier de configuration) * Ceci est notament utilse pour definir des configurations à la volée */ - public function ghost(array|string $key, ?Schema $schema = null): static + public function ghost(array|string $key, array|Schema|null $structure = null): static { + $schema = is_array($structure) ? Expect::mixed($structure) : $structure; + $this->load($key, null, $schema, true); return $this; diff --git a/src/Container/Services.php b/src/Container/Services.php index dc798fe3..e3db8e48 100644 --- a/src/Container/Services.php +++ b/src/Container/Services.php @@ -523,7 +523,7 @@ public static function toolbar(?stdClass $config = null, bool $shared = true): T public static function translator(?string $locale = null, bool $shared = true): Translate { if (null === $locale || $locale === '' || $locale === '0') { - $locale = static::request()->getLocale(); + $locale = is_cli() ? static::config()->get('app.language') : static::request()->getLocale(); } if (true === $shared && isset(static::$instances[Translate::class])) { diff --git a/src/Debug/Toolbar/Collectors/RoutesCollector.php b/src/Debug/Toolbar/Collectors/RoutesCollector.php index 5c77ec5e..9e483b56 100644 --- a/src/Debug/Toolbar/Collectors/RoutesCollector.php +++ b/src/Debug/Toolbar/Collectors/RoutesCollector.php @@ -45,8 +45,8 @@ class RoutesCollector extends BaseCollector public function __construct() { - $rawRoutes = single_service('routes'); - $this->router = single_service('router', $rawRoutes, null); + $rawRoutes = service('routes'); + $this->router = service('router', $rawRoutes, null); $this->definedRouteCollector = new DefinedRouteCollector($rawRoutes); $this->isAutoRoute = $rawRoutes->shouldAutoRoute(); }