From d576d20930a4ad8b66a11060afbabe78506d3ad6 Mon Sep 17 00:00:00 2001 From: Dimitri Sitchet Tomkeu Date: Sun, 23 Aug 2026 15:56:48 +0100 Subject: [PATCH 1/3] chore: publication de la configuration via la commande `config:publish` (framework v1.x) --- src/Config/Registrar.php | 23 +++++++++++++++++ src/Publishers/ParametresPublisher.php | 35 -------------------------- 2 files changed, 23 insertions(+), 35 deletions(-) create mode 100644 src/Config/Registrar.php delete mode 100644 src/Publishers/ParametresPublisher.php diff --git a/src/Config/Registrar.php b/src/Config/Registrar.php new file mode 100644 index 0000000..9d23832 --- /dev/null +++ b/src/Config/Registrar.php @@ -0,0 +1,23 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + +namespace BlitzPHP\Parametres\Config; + +class Registrar +{ + /** + * Enregistre les fichiers de configurations publiable + */ + public static function config(): array + { + return ['parametres']; + } +} diff --git a/src/Publishers/ParametresPublisher.php b/src/Publishers/ParametresPublisher.php deleted file mode 100644 index 99f3cc2..0000000 --- a/src/Publishers/ParametresPublisher.php +++ /dev/null @@ -1,35 +0,0 @@ - - * - * For the full copyright and license information, please view - * the LICENSE file that was distributed with this source code. - */ - -namespace BlitzPHP\Parametres\Publishers; - -use BlitzPHP\Publisher\Publisher; - -class ParametresPublisher extends Publisher -{ - /** - * {@inheritDoc} - */ - protected string $source = __DIR__ . '/../Config/'; - - /** - * {@inheritDoc} - */ - protected string $destination = CONFIG_PATH; - - /** - * {@inheritDoc} - */ - public function publish(): bool - { - return $this->addPaths(['parametres.php'])->merge(false); - } -} From 51bcdd8a29efb9e23cf0845dad0eec19c7d06e0b Mon Sep 17 00:00:00 2001 From: Dimitri Sitchet Tomkeu Date: Sun, 11 Oct 2026 10:46:11 +0100 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20utilisation=20de=20la=20syntaxe=20`?= =?UTF-8?q?dot=20nodation`=20pour=20la=20manupulation=20des=20param=C3=A8t?= =?UTF-8?q?res?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Handlers/ArrayHandler.php | 36 ++++++++++++++++++++++++----------- src/Parametres.php | 16 ++++++++-------- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/Handlers/ArrayHandler.php b/src/Handlers/ArrayHandler.php index 2ac526d..f80fa09 100644 --- a/src/Handlers/ArrayHandler.php +++ b/src/Handlers/ArrayHandler.php @@ -11,6 +11,8 @@ namespace BlitzPHP\Parametres\Handlers; +use BlitzPHP\Utilities\Iterable\Arr; + /** * Gestionnaire de paramètres via des tableaux * @@ -97,10 +99,10 @@ public function flush(): void protected function hasStored(string $file, string $property, ?string $context = null): bool { if ($context === null) { - return isset($this->general[$file]) && array_key_exists($property, $this->general[$file]); + return isset($this->general[$file]) && Arr::has($this->general[$file], $property); } - return isset($this->contexts[$context][$file]) && array_key_exists($property, $this->contexts[$context][$file]); + return isset($this->contexts[$context][$file]) && Arr::has($this->contexts[$context][$file], $property); } /** @@ -114,9 +116,15 @@ protected function getStored(string $file, string $property, ?string $context = return null; } - return $context === null - ? $this->parseValue(...$this->general[$file][$property]) - : $this->parseValue(...$this->contexts[$context][$file][$property]); + $value = $context === null + ? Arr::get($this->general[$file], $property) + : Arr::get($this->contexts[$context][$file], $property); + + if (Arr::dimensions($value) === 2) { + return array_map(fn($v) => $this->parseValue(...$v), $value); + } + + return $this->parseValue(...$value); } /** @@ -128,15 +136,21 @@ protected function setStored(string $file, string $property, mixed $value, ?stri $value = $this->prepareValue($value); if ($context === null) { - $this->general[$file][$property] = [ + if (empty($this->general[$file])) { + $this->general[$file] = []; + } + Arr::set($this->general[$file], $property, [ $value, $type, - ]; + ]); } else { - $this->contexts[$context][$file][$property] = [ + if (empty($this->contexts[$context][$file])) { + $this->contexts[$context][$file] = []; + } + Arr::set($this->contexts[$context][$file], $property, [ $value, $type, - ]; + ]); } } @@ -146,9 +160,9 @@ protected function setStored(string $file, string $property, mixed $value, ?stri protected function forgetStored(string $file, string $property, ?string $context): void { if ($context === null) { - unset($this->general[$file][$property]); + Arr::forget($this->general[$file], $property); } else { - unset($this->contexts[$context][$file][$property]); + Arr::forget($this->contexts[$context][$file], $property); } } diff --git a/src/Parametres.php b/src/Parametres.php index 4d3e30e..8d2ce6e 100644 --- a/src/Parametres.php +++ b/src/Parametres.php @@ -59,7 +59,7 @@ public function __construct(array $config) /** * Récupère une valeur de n'importe quel gestionnaire ou d'un fichier de configuration correspondant au nom file.arg.optionalArg */ - public function get(string $key, ?string $context = null): mixed + public function get(string $key, ?string $context = null, mixed $default = null): mixed { [$file, $property, $config, $dotProperty] = $this->prepareFileAndProperty($key); @@ -67,7 +67,7 @@ public function get(string $key, ?string $context = null): mixed foreach ($this->handlers as $handler) { if ($handler->has($file, $property, $context)) { if (is_array($data = $handler->get($file, $property, $context)) && $property !== $dotProperty) { - return Arr::getRecursive($data, str_replace($property . '.', '', $dotProperty)); + return Arr::get($data, str_replace($property . '.', '', $dotProperty), $default); } return $data; @@ -76,10 +76,10 @@ public function get(string $key, ?string $context = null): mixed // Si aucune valeur contextuelle n'a été trouvée, on revient à la valeur générale. if ($context !== null) { - return $this->get($key); + return $this->get($key, null, $default); } - return Arr::getRecursive($config, $dotProperty); + return Arr::get($config, $dotProperty, $default); } /** @@ -87,10 +87,10 @@ public function get(string $key, ?string $context = null): mixed */ public function set(string $key, mixed $value = null, ?string $context = null): void { - [$file, $property] = $this->prepareFileAndProperty($key); + [$file, , , $dotProperty] = $this->prepareFileAndProperty($key); foreach ($this->getWriteHandlers() as $handler) { - $handler->set($file, $property, $value, $context); + $handler->set($file, $dotProperty, $value, $context); } } @@ -100,10 +100,10 @@ public function set(string $key, mixed $value = null, ?string $context = null): */ public function forget(string $key, ?string $context = null): void { - [$file, $property] = $this->prepareFileAndProperty($key); + [$file, , $dotProperty] = $this->prepareFileAndProperty($key); foreach ($this->getWriteHandlers() as $handler) { - $handler->forget($file, $property, $context); + $handler->forget($file, $dotProperty, $context); } } From 170d2316cb82d7b3f162a85fdc02dae913ea0e86 Mon Sep 17 00:00:00 2001 From: dimtrovich <37987162+dimtrovich@users.noreply.github.com> Date: Sun, 11 Oct 2026 10:59:28 +0000 Subject: [PATCH 3/3] Fix styling --- src/Handlers/ArrayHandler.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Handlers/ArrayHandler.php b/src/Handlers/ArrayHandler.php index f80fa09..65b2cce 100644 --- a/src/Handlers/ArrayHandler.php +++ b/src/Handlers/ArrayHandler.php @@ -121,9 +121,9 @@ protected function getStored(string $file, string $property, ?string $context = : Arr::get($this->contexts[$context][$file], $property); if (Arr::dimensions($value) === 2) { - return array_map(fn($v) => $this->parseValue(...$v), $value); + return array_map(fn ($v) => $this->parseValue(...$v), $value); } - + return $this->parseValue(...$value); }