1. Go to this page and download the library: Download initphp/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/ */
initphp / config example snippets
use InitPHP\Config\Classes;
final class MyAppConfig extends Classes
{
public string $url = 'http://lvh.me';
public string $name = 'LocalHost';
/** @var array<string, string> */
public array $db = [
'host' => 'localhost',
'user' => 'root',
];
}
$config = new MyAppConfig();
$config->get('url'); // "http://lvh.me"
$config->get('db.host'); // "localhost"
$config->get('details', 'Not Found'); // "Not Found"
if ($config->has('name')) {
$config->get('name'); // "LocalHost"
}
use InitPHP\Config\Library;
$config = new Library();
$config->set('site.url', 'http://lvh.me')
->set('site.db.host', 'localhost');
$config->get('site.url'); // "http://lvh.me"
$config->get('SITE.DB.HOST'); // "localhost" (case-insensitive)
use InitPHP\Config\Config;
Config::setArray('site', ['url' => 'http://lvh.me']);
Config::get('site.url'); // "http://lvh.me"
Config::has('site.url'); // true
Config::reset(); // discard the shared instance (useful in tests)
public function setArray(?string $name, array $assoc = []): self;
public function setClass(string|object $classOrObject): self;
namespace App\Config;
class AppConfig
{
public string $url = 'http://lvh.me';
}
class Database
{
public string $host = 'localhost';
}
Config::setClass(\App\Config\AppConfig::class); // by class name
Config::setClass(new \App\Config\Database()); // by instance
Config::get('appconfig.url'); // "http://lvh.me"
Config::get('database.host'); // "localhost"