class Database { protected static $config = []; public function getConnection() { $dsn = self::$config['dsn']; $user = self::$config['user']; $pass = self::$config['pass']; $pdo = new PDO($dsn, $user, $pass); return $pdo; } public static function setConfig($config) { self::$config = $config; } } $config = [ 'dsn' => 'mysql:host=localhost;dbname=test', 'user' => 'root', 'pass' => '' ]; Database::setConfig($config);
class Config { protected static $values = []; public static function get($key) { return self::$values[$key]; } public static function set($key, $value) { self::$values[$key] = $value; } public static function setConfig($config) { foreach($config as $key => $value) { self::$values[$key] = $value; } } } $config = [ 'site_name' => 'My Site', 'site_url' => 'https://example.com' ]; Config::setConfig($config);In this example, the Config class is used to store site-wide configuration values which can be accessed from anywhere in the application. The setConfig method is used to set these values at the start of the application. Package library: None (custom implementation)