PHP code example of mizmoz / config

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

    

mizmoz / config example snippets


$config = new Config(['app' => ...]);
$config->get('app...');

$config = Config::fromDirectory('./config', '.php');
$config->get('app...');

# In a config db.php
return [
    'type' => 'mongo',
    'hostname' => 'db.servers.com',
];

# In another config file for development db.development.php
return \Mizmoz\Config\Extend::production('db', [
    'host' => 'localhost',
]);

# Setup the config from directory
$config = Config::fromEnvironment(Environment::create(__DIR__));
$config->get('db.type'); // mongo
$config->get('db.hostname'); // localhost

# Using the envrionment override to ensure any values that come from the environment variables are treated as priority
# Assuming we do something like:
# export MM_DB_PORT=3333
$config = new Config([
    'db' => [
        'default' => 'mysql',
        'port' => 3306,
    ]
]);

$config->addOverride(new Env);

# Access the value of 3333
$config->get('db.port');

# The same can be done for cli arguments so:
# php my-script.php MM_DB_PORT=5555
$config = new Config([
    'db' => [
        'default' => 'mysql',
        'port' => 3306,
    ]
]);

$config->addOverride(new Args);

# Access the value of 5555
$config->get('db.port');

# These can be chained with last priority so using the above example:
# Returns 5555
$config->addOverride(new Env)
    ->addOverride(new Args)
    ->get('db.port');


$config = new Config([
    'db' => [
        'default' => 'mysql',
        'mysql' => 3306,
    ]
]);

# Basic accessing using dot notation
$config->get('db.default');

# Using the __invoke magic method
$config('db');

# Accessing with other config values referenced
$config->get('db.${db.default}');

# Accessing with relative references
$config->get('db.${.default}');