2017 © Pedro Peláez
 

library console-configuration

Console Configuration Helper implementation.

image

phlib/console-configuration

Console Configuration Helper implementation.

  • Tuesday, February 13, 2018
  • by letssurf
  • Repository
  • 5 Watchers
  • 0 Stars
  • 1,148 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 10 Versions
  • 7 % Grown

The README.md

phlib/console-configuration

Code Checks Codecov Latest Stable Version Total Downloads Licence, (*1)

Console Configuration Helper implementation., (*2)

Install

Via Composer, (*3)

``` bash $ composer require phlib/console-configuration, (*4)


## Configuration Helper Adds the ```-c path/to/config.php``` parameter to the console application and makes it easily accessible to all commands. This is most useful for third party libraries which rely on the configuration being specified from the options. ### Basic Usage ```php // 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);
    }
}

Options

You can specify some options to setup the helper through the initHelper static method., (*5)

Name Type Default Description
name String 'config' The name of the option on the command line.
abbreviation String 'c' The abbreviation of the option on the command line.
description String '...' The associated description for the option.
filename String 'cli-config.php' The filename that will be detected if no name is specified.
ConfigurationHelper::initHelper($app, null, [
    'name' => 'config-option',
    'filename' => 'my-cli-config.php',
]);

Defaults

With no default (null) specified, the fetch method returns false. You can specify a default configuration using the setDefault method or through the initHelper static method., (*6)

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

OR, (*7)

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

Use Case: Autodetect with no command line option

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

License

This package is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version., (*8)

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details., (*9)

You should have received a copy of the GNU Lesser General Public License along with this program. If not, see http://www.gnu.org/licenses/., (*10)

The Versions

13/02 2018

dev-master

9999999-dev

Console Configuration Helper implementation.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

by Luke Richards

configuration console helper symfony option

13/02 2018

1.1.1

1.1.1.0

Console Configuration Helper implementation.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

by Luke Richards

configuration console helper symfony option

03/03 2017

1.1.0

1.1.0.0

Console Configuration Helper implementation.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

by Luke Richards

configuration console helper symfony option

05/07 2016

1.0.3

1.0.3.0

Console Configuration Helper implementation.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Luke Richards

configuration console helper symfony option

03/06 2016

1.0.2

1.0.2.0

Console Configuration Helper implementation.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Luke Richards

configuration console helper symfony option

26/01 2016

1.0.1

1.0.1.0

Console Configuration Helper implementation.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Luke Richards

configuration console helper symfony option

14/12 2015

1.0.0

1.0.0.0

Console Configuration Helper implementation.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Luke Richards

configuration console helper symfony option

24/11 2015

0.2.1

0.2.1.0

Console Configuration Helper implementation.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Luke Richards

configuration console helper symfony option

23/11 2015

0.2

0.2.0.0

Console Configuration Helper implementation.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Luke Richards

configuration console helper symfony option

20/11 2015

0.1

0.1.0.0

Console Configuration Helper implementation.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Luke Richards

configuration console helper symfony option