You've already forked Traefik-Redis-Api
27 lines
632 B
PHP
27 lines
632 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Siteworxpro\App\Helpers;
|
|
|
|
abstract class Env
|
|
{
|
|
/**
|
|
* @param string $key
|
|
* @param null $default
|
|
* @param string $castTo
|
|
* @return float|bool|int|string
|
|
*/
|
|
public static function get(string $key, $default = null, string $castTo = 'string'): float | bool | int | string
|
|
{
|
|
$env = getenv($key) !== false ? getenv($key) : $default;
|
|
|
|
return match ($castTo) {
|
|
'bool', 'boolean' => (bool) $env,
|
|
'int', 'integer' => (int) $env,
|
|
'float' => (float) $env,
|
|
default => (string) $env,
|
|
};
|
|
}
|
|
}
|