1. Go to this page and download the library: Download phpdot/config library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
phpdot / config example snippets
use PHPdot\Config\Configuration;
$config = new Configuration(path: __DIR__ . '/config');
$config->get('database.host'); // 'localhost'
$config->get('database.port'); // 3306
$config->get('database.missing', 'default'); // 'default'
readonly class DatabaseConfig
{
public function __construct(
public string $host,
public int $port,
public string $name,
public string $username,
public string $password = '',
public bool $debug = false,
) {}
}
$db = $config->dto('database', DatabaseConfig::class);
$db->host; // 'prod-db.internal'
$db->port; // 5432 (int, auto-cast)
$db->debug; // false (bool, auto-cast)
readonly class CookieConfig
{
public function __construct(
public bool $secure = true,
public bool $httpOnly = true,
public string $sameSite = 'Lax',
) {}
}
readonly class HttpConfig
{
/**
* @param list<string> $trustedProxies
*/
public function __construct(
public array $trustedProxies = [],
public int $trustedHeaders = 0,
public CookieConfig $cookie = new CookieConfig(),
) {}
}