modifs.mineures sans commentaires
This commit is contained in:
parent
2456a48b38
commit
373910b170
@ -3,6 +3,7 @@ namespace nulib\app;
|
|||||||
|
|
||||||
use nulib\A;
|
use nulib\A;
|
||||||
use nulib\app\cli\Application;
|
use nulib\app\cli\Application;
|
||||||
|
use nulib\app\config\ProfileManager;
|
||||||
use nulib\cl;
|
use nulib\cl;
|
||||||
use nulib\ExitError;
|
use nulib\ExitError;
|
||||||
use nulib\os\path;
|
use nulib\os\path;
|
||||||
@ -97,7 +98,7 @@ class app {
|
|||||||
|
|
||||||
static function params_putenv(): void {
|
static function params_putenv(): void {
|
||||||
$params = serialize(self::get()->getParams());
|
$params = serialize(self::get()->getParams());
|
||||||
putenv("NULIB_APP_app_params=". $params);
|
putenv("NULIB_APP_app_params=$params");
|
||||||
}
|
}
|
||||||
|
|
||||||
static function params_getenv(): ?array {
|
static function params_getenv(): ?array {
|
||||||
@ -107,9 +108,7 @@ class app {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static function get_profile(?bool &$productionMode=null): string {
|
static function get_profile(?bool &$productionMode=null): string {
|
||||||
$app = self::get();
|
return self::get()->getProfile($productionMode);
|
||||||
$productionMode = $app->isProductionMode();
|
|
||||||
return $app->getProfile();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static function set_profile(?string $profile=null, ?bool $productionMode=null): void {
|
static function set_profile(?string $profile=null, ?bool $productionMode=null): void {
|
||||||
@ -137,7 +136,6 @@ class app {
|
|||||||
] = $params;
|
] = $params;
|
||||||
$cwd = $params["cwd"] ?? null;
|
$cwd = $params["cwd"] ?? null;
|
||||||
$datadirIsDefined = true;
|
$datadirIsDefined = true;
|
||||||
$profile = $params["profile"] ?? null;
|
|
||||||
} else {
|
} else {
|
||||||
# projdir
|
# projdir
|
||||||
$projdir = $params["projdir"] ?? null;
|
$projdir = $params["projdir"] ?? null;
|
||||||
@ -190,15 +188,16 @@ class app {
|
|||||||
if ($logdir === false) $logdir = $params["logdir"] ?? null;
|
if ($logdir === false) $logdir = $params["logdir"] ?? null;
|
||||||
if ($logdir === null) $logdir = "log";
|
if ($logdir === null) $logdir = "log";
|
||||||
$logdir = path::reljoin($datadir, $logdir);
|
$logdir = path::reljoin($datadir, $logdir);
|
||||||
# profile
|
|
||||||
$profile = getenv("${APPCODE}_PROFILE");
|
|
||||||
if ($profile === false) $profile = getenv("APP_PROFILE");
|
|
||||||
if ($profile === false) $profile = $params["profile"] ?? null;
|
|
||||||
}
|
}
|
||||||
# cwd
|
# cwd
|
||||||
$cwd ??= getcwd();
|
$cwd ??= getcwd();
|
||||||
# profile
|
# profile
|
||||||
$profile ??= $datadirIsDefined? "prod": "devel";
|
$this->profileManager = new ProfileManager([
|
||||||
|
"app" => true,
|
||||||
|
"name" => $appcode,
|
||||||
|
"default_profile" => $datadirIsDefined? "prod": "devel",
|
||||||
|
"profile" => $params["profile"] ?? null,
|
||||||
|
]);
|
||||||
|
|
||||||
$this->projdir = $projdir;
|
$this->projdir = $projdir;
|
||||||
$this->vendor = $vendor;
|
$this->vendor = $vendor;
|
||||||
@ -208,7 +207,6 @@ class app {
|
|||||||
$this->etcdir = $etcdir;
|
$this->etcdir = $etcdir;
|
||||||
$this->vardir = $vardir;
|
$this->vardir = $vardir;
|
||||||
$this->logdir = $logdir;
|
$this->logdir = $logdir;
|
||||||
$this->profile = $profile;
|
|
||||||
|
|
||||||
# name, title
|
# name, title
|
||||||
$appgroup = $params["appgroup"] ?? null;
|
$appgroup = $params["appgroup"] ?? null;
|
||||||
@ -283,25 +281,18 @@ class app {
|
|||||||
return $this->logdir;
|
return $this->logdir;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected string $profile;
|
protected ProfileManager $profileManager;
|
||||||
|
|
||||||
function getProfile(): string {
|
function getProfile(?bool &$productionMode=null): string {
|
||||||
return $this->profile;
|
return $this->profileManager->getProfile($productionMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected bool $productionMode;
|
|
||||||
|
|
||||||
function isProductionMode(): bool {
|
function isProductionMode(): bool {
|
||||||
return $this->productionMode;
|
return $this->profileManager->isProductionMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
function setProfile(?string $profile, ?bool $productionMode=null): void {
|
function setProfile(?string $profile, ?bool $productionMode=null): void {
|
||||||
$profile ??= $this->profile;
|
$this->profileManager->setProfile($profile, $productionMode);
|
||||||
$this->profile = $profile;
|
|
||||||
if ($productionMode === null) {
|
|
||||||
$productionMode = $profile === "prod" || $profile === "test";
|
|
||||||
}
|
|
||||||
$this->productionMode = $productionMode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -312,7 +303,7 @@ class app {
|
|||||||
*/
|
*/
|
||||||
function withProfile(string $file, $profile): string {
|
function withProfile(string $file, $profile): string {
|
||||||
if ($profile !== false) {
|
if ($profile !== false) {
|
||||||
if ($profile === null) $profile = $this->getProfile();
|
$profile ??= $this->getProfile();
|
||||||
[$dir, $filename] = path::split($file);
|
[$dir, $filename] = path::split($file);
|
||||||
$basename = path::basename($filename);
|
$basename = path::basename($filename);
|
||||||
$ext = path::ext($file);
|
$ext = path::ext($file);
|
||||||
@ -386,7 +377,7 @@ class app {
|
|||||||
"etcdir" => $this->etcdir,
|
"etcdir" => $this->etcdir,
|
||||||
"vardir" => $this->vardir,
|
"vardir" => $this->vardir,
|
||||||
"logdir" => $this->logdir,
|
"logdir" => $this->logdir,
|
||||||
"profile" => $this->le,
|
"profile" => $this->getProfile(),
|
||||||
"appgroup" => $this->appgroup,
|
"appgroup" => $this->appgroup,
|
||||||
"name" => $this->name,
|
"name" => $this->name,
|
||||||
"title" => $this->title,
|
"title" => $this->title,
|
||||||
|
@ -10,15 +10,6 @@ use nulib\cl;
|
|||||||
*/
|
*/
|
||||||
class config {
|
class config {
|
||||||
protected static ConfigManager $config;
|
protected static ConfigManager $config;
|
||||||
protected static ProfileManager $profile;
|
|
||||||
|
|
||||||
static function init(string $appcode): void {
|
|
||||||
self::$config = new ConfigManager();
|
|
||||||
self::$profile = new ProfileManager([
|
|
||||||
"app" => true,
|
|
||||||
"name" => $appcode,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
static function init_configurator($configurators): void {
|
static function init_configurator($configurators): void {
|
||||||
self::$config->addConfigurators(cl::with($configurators));
|
self::$config->addConfigurators(cl::with($configurators));
|
||||||
@ -28,3 +19,9 @@ class config {
|
|||||||
self::$config->configure($params);
|
self::$config->configure($params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new class extends config {
|
||||||
|
function __construct() {
|
||||||
|
self::$config = new ConfigManager();
|
||||||
|
}
|
||||||
|
};
|
@ -55,6 +55,12 @@ class ProfileManager {
|
|||||||
$this->envKeys = [$envKey];
|
$this->envKeys = [$envKey];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$this->defaultProfile = $params["default_profile"] ?? null;
|
||||||
|
$profile = $params["profile"] ?? null;
|
||||||
|
$productionMode = $params["production_mode"] ?? null;
|
||||||
|
$productionMode ??= $this->productionModes[$profile] ?? false;
|
||||||
|
$this->profile = $profile;
|
||||||
|
$this->productionMode = $productionMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -89,7 +95,7 @@ class ProfileManager {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ?string $defaultProfile = null;
|
protected ?string $defaultProfile;
|
||||||
|
|
||||||
function getDefaultProfile(): ?string {
|
function getDefaultProfile(): ?string {
|
||||||
return $this->defaultProfile;
|
return $this->defaultProfile;
|
||||||
@ -99,9 +105,9 @@ class ProfileManager {
|
|||||||
$this->defaultProfile = $profile;
|
$this->defaultProfile = $profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ?string $profile = null;
|
protected ?string $profile;
|
||||||
|
|
||||||
protected bool $productionMode = false;
|
protected bool $productionMode;
|
||||||
|
|
||||||
protected function resolveProfile(): void {
|
protected function resolveProfile(): void {
|
||||||
$profile ??= $this->getenvProfile();
|
$profile ??= $this->getenvProfile();
|
||||||
@ -122,6 +128,10 @@ class ProfileManager {
|
|||||||
return $this->profile;
|
return $this->profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isProductionMode(): bool {
|
||||||
|
return $this->productionMode;
|
||||||
|
}
|
||||||
|
|
||||||
function setProfile(?string $profile=null, ?bool $productionMode=null): void {
|
function setProfile(?string $profile=null, ?bool $productionMode=null): void {
|
||||||
if ($profile === null) $this->profile = null;
|
if ($profile === null) $this->profile = null;
|
||||||
$profile ??= $this->getProfile($productionMode);
|
$profile ??= $this->getProfile($productionMode);
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace nulib {
|
namespace nulib\app {
|
||||||
use nulib\tests\TestCase;
|
use nulib\tests\TestCase;
|
||||||
use nulib\impl\config;
|
use nulib\app\impl\config;
|
||||||
use nulib\impl\myapp;
|
use nulib\app\impl\myapp;
|
||||||
use nulib\impl\MyApplication1;
|
use nulib\app\impl\MyApplication1;
|
||||||
use nulib\impl\MyApplication2;
|
use nulib\app\impl\MyApplication2;
|
||||||
|
|
||||||
class appTest extends TestCase {
|
class appTest extends TestCase {
|
||||||
function testWith() {
|
function testWith() {
|
||||||
@ -19,7 +19,7 @@ namespace nulib {
|
|||||||
"bindir" => "$projdir/vendor/bin",
|
"bindir" => "$projdir/vendor/bin",
|
||||||
"autoload" => "$projdir/vendor/autoload.php",
|
"autoload" => "$projdir/vendor/autoload.php",
|
||||||
],
|
],
|
||||||
"appcode" => "nur-sery",
|
"appcode" => "nur-ture",
|
||||||
"cwd" => $cwd,
|
"cwd" => $cwd,
|
||||||
"datadir" => "$projdir/devel",
|
"datadir" => "$projdir/devel",
|
||||||
"etcdir" => "$projdir/devel/etc",
|
"etcdir" => "$projdir/devel/etc",
|
||||||
@ -38,7 +38,7 @@ namespace nulib {
|
|||||||
"bindir" => "$projdir/vendor/bin",
|
"bindir" => "$projdir/vendor/bin",
|
||||||
"autoload" => "$projdir/vendor/autoload.php",
|
"autoload" => "$projdir/vendor/autoload.php",
|
||||||
],
|
],
|
||||||
"appcode" => "nur-sery",
|
"appcode" => "nur-ture",
|
||||||
"cwd" => $cwd,
|
"cwd" => $cwd,
|
||||||
"datadir" => "$projdir/devel",
|
"datadir" => "$projdir/devel",
|
||||||
"etcdir" => "$projdir/devel/etc",
|
"etcdir" => "$projdir/devel/etc",
|
||||||
@ -63,7 +63,7 @@ namespace nulib {
|
|||||||
"bindir" => "$projdir/vendor/bin",
|
"bindir" => "$projdir/vendor/bin",
|
||||||
"autoload" => "$projdir/vendor/autoload.php",
|
"autoload" => "$projdir/vendor/autoload.php",
|
||||||
],
|
],
|
||||||
"appcode" => "nur-sery",
|
"appcode" => "nur-ture",
|
||||||
"cwd" => $cwd,
|
"cwd" => $cwd,
|
||||||
"datadir" => "$projdir/devel",
|
"datadir" => "$projdir/devel",
|
||||||
"etcdir" => "$projdir/devel/etc",
|
"etcdir" => "$projdir/devel/etc",
|
||||||
@ -82,7 +82,7 @@ namespace nulib {
|
|||||||
"bindir" => "$projdir/vendor/bin",
|
"bindir" => "$projdir/vendor/bin",
|
||||||
"autoload" => "$projdir/vendor/autoload.php",
|
"autoload" => "$projdir/vendor/autoload.php",
|
||||||
],
|
],
|
||||||
"appcode" => "nur-sery",
|
"appcode" => "nur-ture",
|
||||||
"cwd" => $cwd,
|
"cwd" => $cwd,
|
||||||
"datadir" => "$projdir/devel",
|
"datadir" => "$projdir/devel",
|
||||||
"etcdir" => "$projdir/devel/etc",
|
"etcdir" => "$projdir/devel/etc",
|
||||||
@ -97,14 +97,14 @@ namespace nulib {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace nulib\impl {
|
namespace nulib\app\impl {
|
||||||
|
|
||||||
use nulib\app\cli\Application;
|
use nulib\app\cli\Application;
|
||||||
use nulib\os\path;
|
use nulib\os\path;
|
||||||
use nulib\app\app;
|
use nulib\app\app;
|
||||||
|
|
||||||
class config {
|
class config {
|
||||||
const PROJDIR = __DIR__.'/..';
|
const PROJDIR = __DIR__.'/../..';
|
||||||
|
|
||||||
static function get_projdir(): string {
|
static function get_projdir(): string {
|
||||||
return path::abspath(self::PROJDIR);
|
return path::abspath(self::PROJDIR);
|
Loading…
x
Reference in New Issue
Block a user