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