first commit
This commit is contained in:
42
app/Common/Config/Config.php
Executable file
42
app/Common/Config/Config.php
Executable file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
namespace Zampet\Config;
|
||||
|
||||
use Dotenv\Dotenv;
|
||||
|
||||
class Config {
|
||||
private $config = [];
|
||||
private static $instance = null;
|
||||
|
||||
/**
|
||||
* Método construtor
|
||||
*/
|
||||
public function __construct() {
|
||||
// Carrega apenas para $_ENV, não para $_SERVER
|
||||
$dotEnv = Dotenv::createUnsafeImmutable(
|
||||
paths: realpath(path: __DIR__ . "/../../../"),
|
||||
names: '.env'
|
||||
);
|
||||
$dotEnv->safeLoad(); // não dá erro se .env não existir
|
||||
|
||||
// Carrega as configurações
|
||||
$this->config = require_once realpath(path: __DIR__ . "/Consts.php");
|
||||
}
|
||||
|
||||
/**
|
||||
* Retorna a instância única da classe
|
||||
*/
|
||||
public static function getInstance() {
|
||||
if (self::$instance === null) {
|
||||
self::$instance = new Config();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retorna uma configuração
|
||||
*/
|
||||
public function get(string $key) {
|
||||
return $this->config[$key] ?? null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user