Added Runtime Constant compiler

This commit is contained in:
Netkas 2023-01-07 02:49:40 -05:00
parent bb0eb22f26
commit 0010a7257c
2 changed files with 30 additions and 2 deletions

View file

@ -5,4 +5,9 @@
abstract class RuntimeConstants
{
const CWD = '%CWD%';
const PID = '%PID%';
const UID = '%UID%';
const GID = '%GID%';
const User = '%USER%';
}

View file

@ -6,9 +6,8 @@
use ncc\Abstracts\SpecialConstants\DateTimeConstants;
use ncc\Abstracts\SpecialConstants\InstallConstants;
use ncc\Abstracts\SpecialConstants\AssemblyConstants;
use ncc\Abstracts\SpecialConstants\RuntimeConstants;
use ncc\Objects\InstallationPaths;
use ncc\Objects\Package;
use ncc\Objects\ProjectConfiguration;
use ncc\Objects\ProjectConfiguration\Assembly;
class ConstantCompiler
@ -126,4 +125,28 @@
return $input;
}
/**
* @param string|null $input
* @return string|null
* @noinspection PhpUnnecessaryLocalVariableInspection
*/
public static function compileRuntimeConstants(?string $input): ?string
{
if ($input == null)
return null;
if(function_exists('getcwd'))
$input = str_replace(RuntimeConstants::CWD, getcwd(), $input);
if(function_exists('getmypid'))
$input = str_replace(RuntimeConstants::PID, getmypid(), $input);
if(function_exists('getmyuid'))
$input = str_replace(RuntimeConstants::UID, getmyuid(), $input);
if(function_exists('getmygid'))
$input = str_replace(RuntimeConstants::GID, getmygid(), $input);
if(function_exists('get_current_user'))
$input = str_replace(RuntimeConstants::User, get_current_user(), $input);
return $input;
}
}