Making it possible to specify the env name

This commit is contained in:
Pavel Shevaev 2022-07-21 10:57:36 +03:00
parent 7b5b958133
commit 737ace485b
1 changed files with 17 additions and 4 deletions

View File

@ -2,6 +2,8 @@
namespace taskman; namespace taskman;
use Exception; use Exception;
$GLOBALS['TASKMAN_ROOT_ENV_NAME'] = 'gamectl.props.php';
task('envs', function() task('envs', function()
{ {
global $GAME_ROOT; global $GAME_ROOT;
@ -46,16 +48,27 @@ function put_env(&$argv)
putenv("GAME_ENV="); putenv("GAME_ENV=");
} }
function set_root_env_name($root_name)
{
$GLOBALS['TASKMAN_ROOT_ENV_NAME'] = $root_name;
}
function get_root_env_name()
{
return $GLOBALS['TASKMAN_ROOT_ENV_NAME'];
}
function include_env() function include_env()
{ {
global $GAME_ROOT; global $GAME_ROOT;
$env_filename = get_env_file(); $env_filename = get_env_file();
$root_env = get_root_env_name();
if($env_filename && !file_exists($env_filename)) if($env_filename && !file_exists($env_filename))
throw new Exception("Error setting environment. No such env file $env_filename"); throw new Exception("Error setting environment. No such env file $env_filename");
else if($env_filename === null && file_exists("$GAME_ROOT/gamectl.props.php")) else if($env_filename === null && file_exists("$GAME_ROOT/$root_env"))
$env_filename = "$GAME_ROOT/gamectl.props.php"; $env_filename = "$GAME_ROOT/$root_env";
if($env_filename) if($env_filename)
include($env_filename); include($env_filename);
@ -70,9 +83,9 @@ function get_env_file()
$env = getenv("GAME_ENV"); $env = getenv("GAME_ENV");
if($env) if($env)
$env_filename = $GAME_ROOT . "/env/$env.props.php"; $env_filename = "$GAME_ROOT/env/$env.props.php";
else else
$env_filename = $GAME_ROOT . '/gamectl.props.php'; $env_filename = "$GAME_ROOT/" . get_root_env_props_name();
if(file_exists($env_filename)) if(file_exists($env_filename))
return $env_filename; return $env_filename;