Improved environment checking
This commit is contained in:
parent
8718c099f8
commit
d0f5ea233f
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue