modifs.mineures sans commentaires
This commit is contained in:
parent
85f18bd292
commit
fd46d60888
@ -9,6 +9,7 @@ use nulib\ExitError;
|
|||||||
use nulib\os\path;
|
use nulib\os\path;
|
||||||
use nulib\os\sh;
|
use nulib\os\sh;
|
||||||
use nulib\php\func;
|
use nulib\php\func;
|
||||||
|
use nulib\php\types\varray;
|
||||||
use nulib\str;
|
use nulib\str;
|
||||||
use nulib\ValueException;
|
use nulib\ValueException;
|
||||||
use nur\cli\Application as nur_Application;
|
use nur\cli\Application as nur_Application;
|
||||||
@ -83,6 +84,8 @@ class app {
|
|||||||
"vardir",
|
"vardir",
|
||||||
"logdir",
|
"logdir",
|
||||||
"profile",
|
"profile",
|
||||||
|
"facts",
|
||||||
|
"debug",
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
return new static($params, $proj_params !== null);
|
return new static($params, $proj_params !== null);
|
||||||
@ -126,8 +129,8 @@ class app {
|
|||||||
const FACT_WEB_APP = "web-app";
|
const FACT_WEB_APP = "web-app";
|
||||||
const FACT_CLI_APP = "cli-app";
|
const FACT_CLI_APP = "cli-app";
|
||||||
|
|
||||||
static final function is_fact(string $fact): bool {
|
static final function is_fact(string $fact, $value=true): bool {
|
||||||
return self::get()->isFact($fact);
|
return self::get()->isFact($fact, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static final function set_fact(string $fact, $value=true): void {
|
static final function set_fact(string $fact, $value=true): void {
|
||||||
@ -225,6 +228,10 @@ class app {
|
|||||||
"default_profile" => $datadirIsDefined? "prod": "devel",
|
"default_profile" => $datadirIsDefined? "prod": "devel",
|
||||||
"profile" => $params["profile"] ?? null,
|
"profile" => $params["profile"] ?? null,
|
||||||
]);
|
]);
|
||||||
|
# $facts
|
||||||
|
$this->facts = $params["facts"] ?? null;
|
||||||
|
# debug
|
||||||
|
$this->debug = $params["debug"] ?? null;
|
||||||
|
|
||||||
$this->projdir = $projdir;
|
$this->projdir = $projdir;
|
||||||
$this->vendor = $vendor;
|
$this->vendor = $vendor;
|
||||||
@ -324,18 +331,27 @@ class app {
|
|||||||
|
|
||||||
protected ?array $facts;
|
protected ?array $facts;
|
||||||
|
|
||||||
function isFact(string $fact): bool {
|
function isFact(string $fact, $value=true): bool {
|
||||||
return $this->facts[$fact] ?? false;
|
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;
|
$this->facts[$fact] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected bool $debug = false;
|
protected ?bool $debug;
|
||||||
|
|
||||||
function isDebug(): bool {
|
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 {
|
function setDebug(bool $debug=true): void {
|
||||||
@ -425,6 +441,8 @@ class app {
|
|||||||
"vardir" => $this->vardir,
|
"vardir" => $this->vardir,
|
||||||
"logdir" => $this->logdir,
|
"logdir" => $this->logdir,
|
||||||
"profile" => $this->getProfile(),
|
"profile" => $this->getProfile(),
|
||||||
|
"facts" => $this->facts,
|
||||||
|
"debug" => $this->debug,
|
||||||
"appgroup" => $this->appgroup,
|
"appgroup" => $this->appgroup,
|
||||||
"name" => $this->name,
|
"name" => $this->name,
|
||||||
"title" => $this->title,
|
"title" => $this->title,
|
||||||
|
@ -188,6 +188,7 @@ EOT);
|
|||||||
|
|
||||||
protected static function _initialize_app(): void {
|
protected static function _initialize_app(): void {
|
||||||
app::init(static::class);
|
app::init(static::class);
|
||||||
|
app::set_fact(app::FACT_CLI_APP);
|
||||||
msg::set_messenger(new StdMessenger([
|
msg::set_messenger(new StdMessenger([
|
||||||
"min_level" => msg::DEBUG,
|
"min_level" => msg::DEBUG,
|
||||||
]));
|
]));
|
||||||
|
@ -39,11 +39,7 @@ use nulib\str;
|
|||||||
* - CONFIG -- une valeur scalaire
|
* - CONFIG -- une valeur scalaire
|
||||||
*/
|
*/
|
||||||
class EnvConfig implements IConfig{
|
class EnvConfig implements IConfig{
|
||||||
function __construct() {
|
protected ?array $profileConfigs = null;
|
||||||
$this->loadEnvConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected array $profileConfigs;
|
|
||||||
|
|
||||||
/** analyser $name et retourner [$pkey, $profile] */
|
/** analyser $name et retourner [$pkey, $profile] */
|
||||||
private static function parse_pkey_profile($name): array {
|
private static function parse_pkey_profile($name): array {
|
||||||
@ -57,6 +53,7 @@ class EnvConfig implements IConfig{
|
|||||||
}
|
}
|
||||||
|
|
||||||
function loadEnvConfig(): void {
|
function loadEnvConfig(): void {
|
||||||
|
if ($this->profileConfigs !== null) return;
|
||||||
$json_files = [];
|
$json_files = [];
|
||||||
$jsons = [];
|
$jsons = [];
|
||||||
$files = [];
|
$files = [];
|
||||||
@ -96,16 +93,19 @@ class EnvConfig implements IConfig{
|
|||||||
}
|
}
|
||||||
|
|
||||||
function has(string $pkey, string $profile): bool {
|
function has(string $pkey, string $profile): bool {
|
||||||
|
$this->loadEnvConfig();
|
||||||
$config = $this->profileConfigs[$profile] ?? null;
|
$config = $this->profileConfigs[$profile] ?? null;
|
||||||
return cl::phas($config, $pkey);
|
return cl::phas($config, $pkey);
|
||||||
}
|
}
|
||||||
|
|
||||||
function get(string $pkey, string $profile) {
|
function get(string $pkey, string $profile) {
|
||||||
|
$this->loadEnvConfig();
|
||||||
$config = $this->profileConfigs[$profile] ?? null;
|
$config = $this->profileConfigs[$profile] ?? null;
|
||||||
return cl::pget($config, $pkey);
|
return cl::pget($config, $pkey);
|
||||||
}
|
}
|
||||||
|
|
||||||
function set(string $pkey, $value, string $profile): void {
|
function set(string $pkey, $value, string $profile): void {
|
||||||
|
$this->loadEnvConfig();
|
||||||
$config =& $this->profileConfigs[$profile];
|
$config =& $this->profileConfigs[$profile];
|
||||||
cl::pset($config, $pkey, $value);
|
cl::pset($config, $pkey, $value);
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
<?php
|
<?php
|
||||||
require __DIR__."/../vendor/autoload.php";
|
require __DIR__."/../vendor/autoload.php";
|
||||||
|
|
||||||
|
use nulib\app\app;
|
||||||
use nulib\app\cli\Application;
|
use nulib\app\cli\Application;
|
||||||
use nulib\output\msg;
|
use nulib\output\msg;
|
||||||
|
|
||||||
@ -51,6 +52,13 @@ Application::run(new class extends Application {
|
|||||||
private ?array $args = null;
|
private ?array $args = null;
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
|
$profile = app::get_profile($productionMode);
|
||||||
|
$profile = self::get_profile($profile);
|
||||||
|
$productionMode = $productionMode? "production": "development";
|
||||||
|
msg::info("profile=$profile ($productionMode)");
|
||||||
|
$debug = app::is_debug()? "DEBUG": "non";
|
||||||
|
msg::info("debug=$debug");
|
||||||
|
|
||||||
msg::info([
|
msg::info([
|
||||||
"variables:",
|
"variables:",
|
||||||
"\na=", var_export($this->a, true),
|
"\na=", var_export($this->a, true),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user