PHP code example of v-dem / queasy-config

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

    

v-dem / queasy-config example snippets


return [
    'connection' => [
        'driver' => 'mysql',
        'host' => 'localhost',
        'name' => 'test',
        'user' => 'root',
        'password' => 'secret'
    ]
];



$config = new queasy\config\Config('config.php'); // Can be also '.ini', '.json' or '.xml'

$databaseName = $config->database->name;

$databaseName = $config['database']['name'];

// If 'host' is missing in config, 'localhost' will be used by default
$databaseHost = $config['database']->get('host', 'localhost');

// If 'host' is missing in config, 'localhost' will be used by default
$databaseHost = $config['database']('host', 'localhost');

// Throw ConfigException if 'name' is missing
$databaseName = $config['database']->need('name');

$hasDatabaseName = isset($config['database']);
$hasDatabaseName = isset($config['database']['name']);

// $databaseName will contain 'default' if 'name' and/or 'database' options are missing
$databaseName = $config->get('database', [])->get('name', 'default');

// $databaseName will contain 'default' if 'name' and/or 'database' options are missing
$databaseName = $config('database', [])('name', 'default');

return [
    'connection' => [
        'driver' => 'mysql',
        'host' => 'localhost',
        'name' => 'test',
        'user' => 'root',
        'password' => 'secret'
    ],
    'queries' => new queasy\config\Config('queries.php') // Can be config of another type (INI, JSON etc)
];

return [
    'selectActiveUsers' => 'SELECT * FROM `users` WHERE `is_active` = 1'
];

$config = new queasy\config\Config('config.php');
$query = $config['queries']['selectActiveUsers'];

[connection]
driver = mysql
host = localhost
name = test
user = root
password = secret
queries = "@queasy:new queasy\config\Config('queries.ini')"

$defaultConfig = new queasy\config\Config('defaults.php');
$optionalConfig = new queasy\config\Config($arrayWithOptionsToAddOrOverride);
$defaultConfig->merge($optionalConfig);

$config = new queasy\config\Config('.cli');
xml
<?xml version="1.0">
<config>
    <connection
        driver="mysql"
        host="localhost"
        name="test"
        user="root"
        password="secret" />
</config>