PHP code example of phower / config

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

    

phower / config example snippets


// index.php
Config\Config;

// array of options
$options = [
    'host' => 'example.org',
    'email' => '[email protected]',
    'user_name' => 'Pedro',
    'password' => 'Secre7!#@',
];

// create config instance
$config = new Config($options);

// access a configuration key
echo $config->get('email'); // '[email protected]'

// config.php
return [
    'host' => 'example.org',
    'email' => '[email protected]',
    'password' => 'Secre7!#@',
];

// index.php
$config = new Config(

// equivalent methods
echo $config->get('email'); // '[email protected]'
echo $config['email'];      // '[email protected]'
echo $config->email;        // '[email protected]'
echo $config->getEmail();   // '[email protected]'

// always refer same key
echo $config->get('user_name'); // 'Pedro'
echo $config->get('userName');  // 'Pedro'
echo $config->get('USER-NAME'); // 'Pedro'
echo $config->get('username');  // 'Pedro'

// same applies when using different methods of example above

// 1. create instance with read-only mode set to false
$config = new Config(er creation
$config = new Config(

// 1. create instance with allow-override mode set to true
$config = new Config(e after creation
$config = new Config(

// create empty config instance with read-only set to FALSE
$config = new Config([], false);

// set some keys
$config->set('host', 'example.org')
       ->set('email', '[email protected]')
       ->set('user_name', 'Pedro')
       ->set('password', 'Secre7!#@');

// remove one key
$config->remove('user_name');

// setting keys
$config['host'] = 'example.org';
$config->host = 'example.org';
$config->setHost('example.org');

// removing keys
unset($config['host']);
unset($config->host);
$config->removeHost();

// checking 'host' key
echo $config->has('host'); // returns TRUE if exists otherwise FALSE

// alternative interfaces
isset($config['host']);
isset($config->host);
$config->hasHost();

// exporting configuration
$config = new Config($options);
$config->toArray(); // returns $options array

// merging configurations
$config1 = new Config($someOptions);
$config2 = new Config($otherOptions);

$config1->merge($config2); // $otherOptions are merged with $someOptions internally