PHP code example of phlib / console-configuration

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

    

phlib / console-configuration example snippets


// your usual cli setup script

use Phlib\ConsoleConfiguration\Helper\ConfigurationHelper;

$app = new Application('my-cli');
$app->setCommands(['...']);
$helper = ConfigurationHelper::initHelper(
    $app,
    $default = ['host' => 'localhost'],
    $options = []
);
$app->run();


class MyCommand extends Command
{
    '...'

    protected function createMyObjectInstance()
    {
        $config = $this->getHelper('configuration')->fetch();
        return new MyObjectInstance($config);
    }
}

ConfigurationHelper::initHelper($app, null, [
    'name' => 'config-option',
    'filename' => 'my-cli-config.php',
]);

$helper->setDefault(['host' => 'localhost']);

ConfigurationHelper::initHelper(
    $app,
    ['host' => 'localhost'],
    ['filename' => 'service-name.php']
);

$app = new Application('my-cli');
$app->setCommands(['...']);
$app->getHelperSet()->set(new ConfigurationHelper('config', 'my-config.php'));
$app->run();