PHP-Course/exam/config/Config.php

57 lines
1.0 KiB
PHP

<?php
namespace Config;
class Config
{
private static array $instances = [];
private array $app;
private array $database;
protected function __construct()
{
$this->app = require_once __DIR__ . "/app.php";
$this->database = require_once __DIR__ . "/database.php";
}
protected function __clone()
{
}
public function __wakeup()
{
throw new \Exception("Cannot unserialize a singleton.");
}
private static function getInstance(): Config
{
$cls = static::class;
if (!isset(self::$instances[$cls])) {
self::$instances[$cls] = new static();
}
return self::$instances[$cls];
}
public static function getBasePath()
{
return Config::getInstance()->app["basePath"];
}
public static function getBaseFSPath()
{
return Config::getInstance()->app["baseFSPath"];
}
public static function getStoragePath()
{
return Config::getInstance()->app["storagePath"];
}
public static function getDatabase()
{
return Config::getInstance()->database;
}
}