mirror of
https://github.com/SociallyDev/Spaces-API.git
synced 2025-08-20 13:23:47 -07:00
v2: Updates
* Simplifies & beautifies everything * Introduces a new Class system. * Errors are defaulted to AWS's handler. * New function names & more efficient handling. * Should fix a majority of the errors. Please read the README for more!
This commit is contained in:
parent
ad0726e41e
commit
e6d7753dc8
1095 changed files with 45088 additions and 2911 deletions
|
@ -20,14 +20,16 @@ final class Env
|
|||
* @param string $expression JMESPath expression to evaluate
|
||||
* @param mixed $data JSON-like data to search
|
||||
*
|
||||
* @return mixed|null Returns the matching data or null
|
||||
* @return mixed Returns the matching data or null
|
||||
*/
|
||||
public static function search($expression, $data)
|
||||
{
|
||||
static $runtime;
|
||||
|
||||
if (!$runtime) {
|
||||
$runtime = Env::createRuntime();
|
||||
}
|
||||
|
||||
return $runtime($expression, $data);
|
||||
}
|
||||
|
||||
|
@ -39,7 +41,7 @@ final class Env
|
|||
*/
|
||||
public static function createRuntime()
|
||||
{
|
||||
switch ($compileDir = getenv(self::COMPILE_DIR)) {
|
||||
switch ($compileDir = self::getEnvVariable(self::COMPILE_DIR)) {
|
||||
case false: return new AstRuntime();
|
||||
case 'on': return new CompilerRuntime();
|
||||
default: return new CompilerRuntime($compileDir);
|
||||
|
@ -55,7 +57,8 @@ final class Env
|
|||
public static function cleanCompileDir()
|
||||
{
|
||||
$total = 0;
|
||||
$compileDir = getenv(self::COMPILE_DIR) ?: sys_get_temp_dir();
|
||||
$compileDir = self::getEnvVariable(self::COMPILE_DIR) ?: sys_get_temp_dir();
|
||||
|
||||
foreach (glob("{$compileDir}/jmespath_*.php") as $file) {
|
||||
$total++;
|
||||
unlink($file);
|
||||
|
@ -63,4 +66,26 @@ final class Env
|
|||
|
||||
return $total;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an environment variable from $_SERVER, $_ENV or via getenv().
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
private static function getEnvVariable($name)
|
||||
{
|
||||
if (array_key_exists($name, $_SERVER)) {
|
||||
return $_SERVER[$name];
|
||||
}
|
||||
|
||||
if (array_key_exists($name, $_ENV)) {
|
||||
return $_ENV[$name];
|
||||
}
|
||||
|
||||
$value = getenv($name);
|
||||
|
||||
return $value === false ? null : $value;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue