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\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, | ||||
|  | ||||
| @ -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, | ||||
|     ])); | ||||
|  | ||||
| @ -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); | ||||
|   } | ||||
|  | ||||
| @ -2,6 +2,7 @@ | ||||
| <?php | ||||
| require __DIR__."/../vendor/autoload.php"; | ||||
| 
 | ||||
| use nulib\app\app; | ||||
| use nulib\app\cli\Application; | ||||
| use nulib\output\msg; | ||||
| 
 | ||||
| @ -51,6 +52,13 @@ Application::run(new class extends Application { | ||||
|   private ?array $args = null; | ||||
| 
 | ||||
|   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([ | ||||
|       "variables:", | ||||
|       "\na=", var_export($this->a, true), | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user