From fd46d6088856d2a3f1f8a8aa441b08aa1eec8f43 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Thu, 2 Oct 2025 13:35:15 +0400 Subject: [PATCH] modifs.mineures sans commentaires --- src/app/app.php | 32 +++++++++++++++++++++++++------- src/app/cli/Application.php | 1 + src/app/config/EnvConfig.php | 10 +++++----- tbin/test-application.php | 8 ++++++++ 4 files changed, 39 insertions(+), 12 deletions(-) diff --git a/src/app/app.php b/src/app/app.php index 8022a3a..52bfc79 100644 --- a/src/app/app.php +++ b/src/app/app.php @@ -9,6 +9,7 @@ use nulib\ExitError; use nulib\os\path; use nulib\os\sh; use nulib\php\func; +use nulib\php\types\varray; use nulib\str; use nulib\ValueException; use nur\cli\Application as nur_Application; @@ -83,6 +84,8 @@ class app { "vardir", "logdir", "profile", + "facts", + "debug", ])); } return new static($params, $proj_params !== null); @@ -126,8 +129,8 @@ class app { const FACT_WEB_APP = "web-app"; const FACT_CLI_APP = "cli-app"; - static final function is_fact(string $fact): bool { - return self::get()->isFact($fact); + static final function is_fact(string $fact, $value=true): bool { + return self::get()->isFact($fact, $value); } static final function set_fact(string $fact, $value=true): void { @@ -225,6 +228,10 @@ class app { "default_profile" => $datadirIsDefined? "prod": "devel", "profile" => $params["profile"] ?? null, ]); + # $facts + $this->facts = $params["facts"] ?? null; + # debug + $this->debug = $params["debug"] ?? null; $this->projdir = $projdir; $this->vendor = $vendor; @@ -324,18 +331,27 @@ class app { protected ?array $facts; - function isFact(string $fact): bool { - return $this->facts[$fact] ?? false; + function isFact(string $fact, $value=true): bool { + return ($this->facts[$fact] ?? false) === $value; } - function setFact(string $fact, bool $value=true): void { + function setFact(string $fact, $value=true): void { $this->facts[$fact] = $value; } - protected bool $debug = false; + protected ?bool $debug; function isDebug(): bool { - return $this->debug; + $debug = $this->debug; + if ($debug === null) { + $debug = defined("DEBUG")? DEBUG: null; + $DEBUG = getenv("DEBUG"); + $debug ??= $DEBUG !== false? $DEBUG: null; + $debug ??= config::k("debug"); + $debug ??= false; + $this->debug = $debug; + } + return $debug; } function setDebug(bool $debug=true): void { @@ -425,6 +441,8 @@ class app { "vardir" => $this->vardir, "logdir" => $this->logdir, "profile" => $this->getProfile(), + "facts" => $this->facts, + "debug" => $this->debug, "appgroup" => $this->appgroup, "name" => $this->name, "title" => $this->title, diff --git a/src/app/cli/Application.php b/src/app/cli/Application.php index 6d26e2a..d130eee 100644 --- a/src/app/cli/Application.php +++ b/src/app/cli/Application.php @@ -188,6 +188,7 @@ EOT); protected static function _initialize_app(): void { app::init(static::class); + app::set_fact(app::FACT_CLI_APP); msg::set_messenger(new StdMessenger([ "min_level" => msg::DEBUG, ])); diff --git a/src/app/config/EnvConfig.php b/src/app/config/EnvConfig.php index 0d93173..b07bf47 100644 --- a/src/app/config/EnvConfig.php +++ b/src/app/config/EnvConfig.php @@ -39,11 +39,7 @@ use nulib\str; * - CONFIG -- une valeur scalaire */ class EnvConfig implements IConfig{ - function __construct() { - $this->loadEnvConfig(); - } - - protected array $profileConfigs; + protected ?array $profileConfigs = null; /** analyser $name et retourner [$pkey, $profile] */ private static function parse_pkey_profile($name): array { @@ -57,6 +53,7 @@ class EnvConfig implements IConfig{ } function loadEnvConfig(): void { + if ($this->profileConfigs !== null) return; $json_files = []; $jsons = []; $files = []; @@ -96,16 +93,19 @@ class EnvConfig implements IConfig{ } function has(string $pkey, string $profile): bool { + $this->loadEnvConfig(); $config = $this->profileConfigs[$profile] ?? null; return cl::phas($config, $pkey); } function get(string $pkey, string $profile) { + $this->loadEnvConfig(); $config = $this->profileConfigs[$profile] ?? null; return cl::pget($config, $pkey); } function set(string $pkey, $value, string $profile): void { + $this->loadEnvConfig(); $config =& $this->profileConfigs[$profile]; cl::pset($config, $pkey, $value); } diff --git a/tbin/test-application.php b/tbin/test-application.php index f85ad10..44596eb 100755 --- a/tbin/test-application.php +++ b/tbin/test-application.php @@ -2,6 +2,7 @@ a, true),