ajout cachedir
This commit is contained in:
parent
394edb782e
commit
c62de542c3
@ -1,8 +1,5 @@
|
||||
# nulib\app
|
||||
|
||||
* [ ] ajouter des méthodes normalisées `app::get_cachedir()` et
|
||||
`app::get_cachefile($name)` avec la valeur par défaut
|
||||
`cachedir = $vardir/cache`
|
||||
* [ ] `app::action()` et `app::step()` appellent automatiquement
|
||||
`app::_dispatch_signals()`
|
||||
|
||||
|
@ -36,6 +36,7 @@ class app {
|
||||
"datadir" => $app::DATADIR,
|
||||
"etcdir" => $app::ETCDIR,
|
||||
"vardir" => $app::VARDIR,
|
||||
"cachedir" => $app::CACHEDIR,
|
||||
"logdir" => $app::LOGDIR,
|
||||
"appgroup" => $app::APPGROUP,
|
||||
"name" => $app::NAME,
|
||||
@ -51,6 +52,7 @@ class app {
|
||||
"datadir" => constant("$app::DATADIR"),
|
||||
"etcdir" => constant("$app::ETCDIR"),
|
||||
"vardir" => constant("$app::VARDIR"),
|
||||
"cachedir" => constant("$app::CACHEDIR"),
|
||||
"logdir" => constant("$app::LOGDIR"),
|
||||
"appgroup" => constant("$app::APPGROUP"),
|
||||
"name" => constant("$app::NAME"),
|
||||
@ -84,6 +86,7 @@ class app {
|
||||
"datadir",
|
||||
"etcdir",
|
||||
"vardir",
|
||||
"cachedir",
|
||||
"logdir",
|
||||
"profile",
|
||||
"facts",
|
||||
@ -172,6 +175,7 @@ class app {
|
||||
"datadir" => $datadir,
|
||||
"etcdir" => $etcdir,
|
||||
"vardir" => $vardir,
|
||||
"cachedir" => $cachedir,
|
||||
"logdir" => $logdir,
|
||||
] = $params;
|
||||
$cwd = $params["cwd"] ?? null;
|
||||
@ -223,6 +227,11 @@ class app {
|
||||
if ($vardir === false) $vardir = $params["vardir"] ?? null;
|
||||
if ($vardir === null) $vardir = "var";
|
||||
$vardir = path::reljoin($datadir, $vardir);
|
||||
# cachedir
|
||||
$cachedir = getenv("${PROJCODE}_CACHEDIR");
|
||||
if ($cachedir === false) $cachedir = $params["cachedir"] ?? null;
|
||||
if ($cachedir === null) $cachedir = "cache";
|
||||
$cachedir = path::reljoin($vardir, $cachedir);
|
||||
# logdir
|
||||
$logdir = getenv("${PROJCODE}_LOGDIR");
|
||||
if ($logdir === false) $logdir = $params["logdir"] ?? null;
|
||||
@ -250,6 +259,7 @@ class app {
|
||||
$this->datadir = $datadir;
|
||||
$this->etcdir = $etcdir;
|
||||
$this->vardir = $vardir;
|
||||
$this->cachedir = $cachedir;
|
||||
$this->logdir = $logdir;
|
||||
|
||||
# name, title
|
||||
@ -319,6 +329,12 @@ class app {
|
||||
return $this->vardir;
|
||||
}
|
||||
|
||||
protected string $cachedir;
|
||||
|
||||
function getCachedir(): string {
|
||||
return $this->cachedir;
|
||||
}
|
||||
|
||||
protected string $logdir;
|
||||
|
||||
function getLogdir(): string {
|
||||
@ -449,6 +465,7 @@ class app {
|
||||
"datadir" => $this->datadir,
|
||||
"etcdir" => $this->etcdir,
|
||||
"vardir" => $this->vardir,
|
||||
"cachedir" => $this->cachedir,
|
||||
"logdir" => $this->logdir,
|
||||
"profile" => $this->getProfile(),
|
||||
"facts" => $this->facts,
|
||||
@ -464,7 +481,7 @@ class app {
|
||||
* une valeur de la forme "$ETCDIR/$name[.$profile].conf"
|
||||
*/
|
||||
function getEtcfile(?string $name=null, $profile=null): string {
|
||||
if ($name === null) $name = "{$this->name}.conf";
|
||||
$name ??= "{$this->name}.conf";
|
||||
return $this->findFile([$this->etcdir], [$name], $profile);
|
||||
}
|
||||
|
||||
@ -473,13 +490,25 @@ class app {
|
||||
* valeur de la forme "$VARDIR/$appgroup/$name[.$profile].tmp"
|
||||
*/
|
||||
function getVarfile(?string $name=null, $profile=null): string {
|
||||
if ($name === null) $name = "{$this->name}.tmp";
|
||||
$name ??= "{$this->name}.tmp";
|
||||
$file = $this->fencedJoin($this->vardir, $this->appgroup, $name);
|
||||
$file = $this->withProfile($file, $profile);
|
||||
sh::mkdirof($file);
|
||||
return $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* obtenir le chemin vers le fichier de cache. par défaut, retourner une
|
||||
* valeur de la forme "$CACHEDIR/$appgroup/$name[.$profile].cache"
|
||||
*/
|
||||
function getCachefile(?string $name=null, $profile=null): string {
|
||||
$name ??= "{$this->name}.cache";
|
||||
$file = $this->fencedJoin($this->cachedir, $this->appgroup, $name);
|
||||
$file = $this->withProfile($file, $profile);
|
||||
sh::mkdirof($file);
|
||||
return $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* obtenir le chemin vers le fichier de log. par défaut, retourner une
|
||||
* valeur de la forme "$LOGDIR/$appgroup/$name.log" (sans le profil, parce
|
||||
@ -493,10 +522,10 @@ class app {
|
||||
$name = "{$this->name}.log";
|
||||
$profile ??= false;
|
||||
}
|
||||
$file = $this->fencedJoin($this->logdir, $this->appgroup, $name);
|
||||
$file = $this->withProfile($file, $profile);
|
||||
sh::mkdirof($file);
|
||||
return $file;
|
||||
$logfile = $this->fencedJoin($this->logdir, $this->appgroup, $name);
|
||||
$logfile = $this->withProfile($logfile, $profile);
|
||||
sh::mkdirof($logfile);
|
||||
return $logfile;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -67,6 +67,7 @@ abstract class Application {
|
||||
const DATADIR = null;
|
||||
const ETCDIR = null;
|
||||
const VARDIR = null;
|
||||
const CACHEDIR = null;
|
||||
const LOGDIR = null;
|
||||
|
||||
/** @var bool faut-il activer automatiquement l'écriture dans les logs */
|
||||
|
@ -132,7 +132,7 @@ class ConfigManager {
|
||||
}
|
||||
|
||||
$value = $this->_getValue($pkey, $default, $inProfile);
|
||||
$this->cacheSet($pkey, $default, $inProfile);
|
||||
$this->cacheSet($pkey, $value, $inProfile);
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user