From fe86739150285fbae7ae0f08a8ca2e08845144fd Mon Sep 17 00:00:00 2001 From: Dimitri Sitchet Tomkeu Date: Wed, 15 Jan 2025 21:28:27 +0100 Subject: [PATCH 1/5] =?UTF-8?q?patch:=20possibilit=C3=A9=20de=20d=C3=A9fin?= =?UTF-8?q?ir=20les=20donn=C3=A9es=20d'une=20configuration=20fantome?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Config/Config.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Config/Config.php b/src/Config/Config.php index 4d761f23..5362efe7 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, null|array|Schema $structure = null): static { + $schema = is_array($structure) ? Expect::mixed($structure) : $structure; + $this->load($key, null, $schema, true); return $this; From eaaddd5464c8db41d00b9061653a3e41c8a568d3 Mon Sep 17 00:00:00 2001 From: Dimitri Sitchet Tomkeu Date: Wed, 15 Jan 2025 21:35:22 +0100 Subject: [PATCH 2/5] =?UTF-8?q?fix:=20service=20`translator`:=20impossibil?= =?UTF-8?q?it=C3=A9=20de=20charger=20les=20traductions=20en=20console?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Container/Services.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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])) { From 637bf22074d12fe5c5da3472a7b6dac9b76b8d8d Mon Sep 17 00:00:00 2001 From: Dimitri Sitchet Tomkeu Date: Tue, 21 Jan 2025 11:50:22 +0100 Subject: [PATCH 3/5] =?UTF-8?q?fix:=20RoutesCollector=20doit=20utiliser=20?= =?UTF-8?q?les=20services=20partag=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Debug/Toolbar/Collectors/RoutesCollector.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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(); } From 5834841fa7ac4e5b225180fb4adaddd5caef07b7 Mon Sep 17 00:00:00 2001 From: Dimitri Sitchet Tomkeu Date: Tue, 21 Jan 2025 16:55:41 +0100 Subject: [PATCH 4/5] fix: correction de la recuperation des parametres de la console lors de leurs enregistrement, les parametres (options et arguments) des commandes sont convertis en camelcase. ce qui fait que pour un parametre ayant 2 parties (en kebabcase), on ne pouvait pas le recuperer --- src/Cli/Console/Command.php | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/Cli/Console/Command.php b/src/Cli/Console/Command.php index c2672bf5..13a549e1 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; } /** @@ -390,8 +403,8 @@ final public function newLine(): self /** * Générer une table pour la console. Les clés de la première ligne sont prises comme en-tête. * - * @param list $rows Tableau de tableaux associés. - * @param array $styles Par exemple : ['head' => 'bold', 'odd' => 'comment', 'even' => 'green'] + * @param array[] $rows Tableau de tableaux associés. + * @param array $styles Par exemple : ['head' => 'bold', 'odd' => 'comment', 'even' => 'green'] */ final public function table(array $rows, array $styles = []): self { @@ -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(); From 0fc4e7bfab610f3b3ce5b9ed6572077fdd6bcd69 Mon Sep 17 00:00:00 2001 From: dimtrovich <37987162+dimtrovich@users.noreply.github.com> Date: Tue, 21 Jan 2025 15:59:19 +0000 Subject: [PATCH 5/5] Fix styling --- src/Cli/Console/Command.php | 22 +++++++++++----------- src/Config/Config.php | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Cli/Console/Command.php b/src/Cli/Console/Command.php index 13a549e1..2fcf849a 100644 --- a/src/Cli/Console/Command.php +++ b/src/Cli/Console/Command.php @@ -225,9 +225,9 @@ final public function setArguments(array $arguments = []): self */ final public function argument(string $name, mixed $default = null): mixed { - if (isset($this->_arguments[$name])) { - return $this->_arguments[$name]; - } + if (isset($this->_arguments[$name])) { + return $this->_arguments[$name]; + } return $this->_arguments[Text::camel($name)] ?? $default; } @@ -245,9 +245,9 @@ final public function getArg(string $name, mixed $default = null) */ final public function option(string $name, mixed $default = null): mixed { - if (isset($this->_options[$name])) { - return $this->_options[$name]; - } + if (isset($this->_options[$name])) { + return $this->_options[$name]; + } return $this->_options[Text::camel($name)] ?? $default; } @@ -267,9 +267,9 @@ final public function param(string $name, mixed $default = null): mixed { $params = array_merge($this->_arguments, $this->_options); - if (isset($params[$name])) { - return $params[$name]; - } + if (isset($params[$name])) { + return $params[$name]; + } return $params[Text::camel($name)] ?? $default; } @@ -403,8 +403,8 @@ final public function newLine(): self /** * Générer une table pour la console. Les clés de la première ligne sont prises comme en-tête. * - * @param array[] $rows Tableau de tableaux associés. - * @param array $styles Par exemple : ['head' => 'bold', 'odd' => 'comment', 'even' => 'green'] + * @param list $rows Tableau de tableaux associés. + * @param array $styles Par exemple : ['head' => 'bold', 'odd' => 'comment', 'even' => 'green'] */ final public function table(array $rows, array $styles = []): self { diff --git a/src/Config/Config.php b/src/Config/Config.php index 5362efe7..46269092 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -154,9 +154,9 @@ 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, null|array|Schema $structure = null): static + public function ghost(array|string $key, array|Schema|null $structure = null): static { - $schema = is_array($structure) ? Expect::mixed($structure) : $structure; + $schema = is_array($structure) ? Expect::mixed($structure) : $structure; $this->load($key, null, $schema, true);