PHP code example of php-strict / config

1. Go to this page and download the library: Download php-strict/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/ */

    

php-strict / config example snippets


use PhpStrict\Config\Config

class AppConfig extends Config
{
    /**
     * Project root
     * 
     * @var string
     */
    public $root = '/';
    
    /**
     * Debug enable|disable
     * 
     * @var bool
     */
    public $debug = false;
    
    /**
     * Database settings
     */
    public $dbServer = '';
    public $dbUser = '';
    public $dbPassword = '';
    public $dbName = '';
    public $dbCharset = '';
    public $dbTablePrefix = ''
    
    /*
     * another configuration fields here
     */
    
}

$config = new AppConfig();
$config->loadFromFile('config.ini');

mysqli::__construct(
    $config->dbServer, 
    $config->dbUser, 
    $config->dbPassword, 
    $config->dbName
);

$dbConfig = $config->getSlice('db');

mysqli::__construct(
    $dbConfig->server, 
    $dbConfig->user, 
    $dbConfig->password, 
    $dbConfig->name
);
ini
DEBUG=true

DB_SERVER=localhost
DB_USER=root
DB_PASSWORD=
DB_NAME=testproject
DB_CHARSET=utf8
DB_TABLE_PREFIX=

CACHE=true