You've already forked Php-Template
TODO: Replace stubs
This commit is contained in:
32
src/Helpers/Config.php
Normal file
32
src/Helpers/Config.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Siteworxpro\App\Helpers;
|
||||
|
||||
use Psr\Log\LogLevel;
|
||||
use Siteworxpro\App\Facades\Config as FacadeConfig;
|
||||
|
||||
class Config
|
||||
{
|
||||
private const array DEFAULTS = [
|
||||
FacadeConfig::DB_DRIVER => 'pgsql',
|
||||
FacadeConfig::DB_HOST => 'localhost',
|
||||
FacadeConfig::DB_DATABASE => 'siteworx',
|
||||
FacadeConfig::DB_USER => 'siteworx',
|
||||
FacadeConfig::DB_PASSWORD => 'password',
|
||||
FacadeConfig::LOG_LEVEL => LogLevel::DEBUG,
|
||||
FacadeConfig::HTTP_PORT => '9501',
|
||||
FacadeConfig::DEV_MODE => true,
|
||||
];
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param string $castTo
|
||||
* @return string|int|bool|float
|
||||
*/
|
||||
public function get(string $key, string $castTo = 'string'): string|int|bool|float
|
||||
{
|
||||
return Env::get($key, self::DEFAULTS[$key] ?? null, $castTo);
|
||||
}
|
||||
}
|
||||
26
src/Helpers/Env.php
Normal file
26
src/Helpers/Env.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?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,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user