PHP code example of loilo / simple-config

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

    

loilo / simple-config example snippets


use Loilo\SimpleConfig\Config;

$config = new Config();

$config->set('foo', 'bar');
$config->get('foo') === 'bar';
 
// Use dot notation to access nested options
$config->set('baz.qux', true);
$config->get('baz') === [ 'qux' => true ];
 
$config->delete('foo');
$config->get('foo') === null;

  $config->has('option')
  

  $config->get('option')
  

  $config->get('nonexistent_option', 'fallback value')
  

  $config->get()
  

  $config->set('option', 'value')
  

  $config->set([
      'option-1' => 'value-1',
      'option-2' => 'value-2'
  ])
  

  $config->delete('option')
  

  $config->delete()
  

use Loilo\SimpleConfig\StaticConfig;
use Loilo\SimpleConfig\Config;

class AppConfig extends StaticConfig
{
    public static function createConfig(): Config
    {
        return new Config();
    }
}

AppConfig::set('foo', 'bar');
AppConfig::get('foo') === 'bar';

$config = new Config([
  // options go here
]);
js
$config->set([
    'foo' => [
        'bar' => [
            'foobar' => 'qux'
        ]
    ]
]);

// With dot notation enabled:
$config->get('foo.bar.foobar') === 'qux';
$config->get('foo')['bar']['foobar'] === 'qux';

// With dot notation disabled:
$config->get('foo.bar.foobar') === null;
$config->get('foo')['bar']['foobar'] === 'qux';