Improved environment checking

This commit is contained in:
Niko 2022-02-10 02:50:21 +01:00
parent 8718c099f8
commit d0f5ea233f
2 changed files with 10 additions and 4 deletions

View File

@ -18,8 +18,7 @@ function tpl($ns, $args=[]) {
function tpl_file($name, $dir, $ext) {
$suffix = '';
$name = str_replace('.', '/', $name);
if (getenv('env') === DEV)
$suffix = '?_='.microtime();
if (env(DEV)) $suffix = '?_='.microtime();
return APP_DIR.'/'.$dir.'/'.$name.'.'.$ext.$suffix;
}

View File

@ -1,17 +1,24 @@
<?php
chdir( $_SERVER['DOCUMENT_ROOT'] );
define('APP_DIR', '/app');
define('PROD', 'prod');
define('DEV', 'dev');
$env = getenv('ENV');
if (!in_array($env, [PROD, DEV]))
$env = DEV;
putenv('env='.$env);
if ($env === PROD) {
ini_set('display_errors', 0);
}
$GLOBALS['environment'] = $env;
function env($which = null) {
if ($which === null)
return $GLOBALS['environment'];
return $GLOBALS['environment'] === $which;
}
$uri = rtrim(trim($_SERVER['REQUEST_URI']),'/');
$app_uri = preg_replace('/^'.preg_quote(