PHP code example of ghostwriter / config

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

    

ghostwriter / config example snippets


$key = 'nested';
$path = 'path/to/config.php';
$options = [
    'settings' => [
        'enable' => true,
    ],
];

$config = $configFactory->create($options);
$config->toArray(); // ['settings' => ['enable'=>true]]

$config = Config::fromPath($path);
$config->toArray(); // ['settings' => ['enable'=>true]]

$config = Config::fromPath($path, $key);
$config->toArray(); // ['nested' => ['settings' => ['enable'=>true]]]
$config->has('nested.settings.disabled'); // true

//

$config = new Config($options);
$config->has('settings'); // true
$config->has('settings.enable'); // true
$config->get('settings.enable'); // true

$config = Config::new($options);
$config->has('settings.disabled'); // false
$config->get('settings.disabled'); // null
$config->get('settings.disabled', 'default'); // 'default'

$config->set('settings.disabled', false); // true
$config->has('settings.disabled'); // true

$config->get('settings.disabled'); // false

$config->toArray(); // ['settings' => ['enable'=>true,'disabled'=>false]]

$config->remove('settings.disabled');

$config->get('settings.disabled'); // null

$config->toArray(); // ['settings' => ['enable'=>true]]

interface ConfigInterface
{
    public function get(string $key, mixed $default = null): mixed;

    public function has(string $key): bool;

    public function remove(string $key): void;

    public function set(string $key, mixed $value): void;

    public function toArray(): array;
}