2017 © Pedro Peláez
 

cakephp-plugin cakephp-config-read

A CakePHP plugin that provides a Shell to read an app's Configure vars from the command line.

image

loadsys/cakephp-config-read

A CakePHP plugin that provides a Shell to read an app's Configure vars from the command line.

  • Monday, October 3, 2016
  • by jtyost2
  • Repository
  • 10 Watchers
  • 3 Stars
  • 9,906 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 1 Forks
  • 2 Open issues
  • 20 Versions
  • 7 % Grown

The README.md

CakePHP-ConfigReadShell

Latest Version Build Status Coverage Status Software License Total Downloads, (*1)

A CakePHP plugin that provides a Shell to read an app's Configure vars from the command line., (*2)

Installation

Use the following as a guide for choosing your version based on the version of CakePHP installed., (*3)

CakePHP ConfigReadShell Plugin Tag Notes
^3.4 master 4.0.0 stable
3.3 3.3 3.0.0 stable
2.5 2.x 2.0.1 stable
1.3 1.x 1.0.1 stable

This will install the latest version.

$ composer require loadsys/cakephp-config-read:~4.0

Note: we don't expect to actively maintain or improve the 1.3 version. It's here because the project started life as a 1.3 Shell., (*4)

Requirements

  • PHP 7.0+
  • CakePHP 3.6.0+

Usage

Imagine the following defined in config/app.php:, (*5)

return [
    'Key' => [
        'Name' => 'foo',
    ],
    'Second' => [
        'Key' => [
            'First' => 'bar',
            'Second' => 'baz',
            'Third' => 42,
        ],
    ],
];

To use this plugin, call it from the command line:, (*6)

$ cd path/to/app/
$ ./bin/cake config_read Key.Name
'foo'

Format as a bash variable definition

$ ./bin/cake ConfigRead.ConfigRead Key.Name Second.Key
KEY_NAME='foo'
SECOND_KEY_FIRST='bar'
SECOND_KEY_SECOND='baz'
SECOND_KEY_THIRD='42'

Note that this format is automatically used whenever more than one key is returned (unless the --serialize switch has been used). For example, if you request a key that contains an array, all values in the array will be returned sequentially. Alternatively, if you pass multiple keys on the command line, they will all be returned. The format can also be forced using the -b or --bash command line switch:, (*7)

$ ./bin/cake config_read -b Key.Name
KEY_NAME='foo'

Serializing output

It is possible serialize the output from ConfigReadShell so that it can be consumed by other PHP scripts more easily by using the -s or --serialize command line switch., (*8)

Requesting multiple keys on the command line will produce an array of those keys. Requesting a single scalar value will produce only that scalar value., (*9)

This switch always overrides both the --bash switch and the Shell's automatic bash formatting., (*10)

$ ./bin/cake config_read -s Key.Name Second.Key
a:2:{s:8:"Key.Name";s:3:"foo";s:10:"Second.Key";a:3:{s:5:"First";s:3:"bar";s:6:"Second";s:3:"baz";s:5:"Third";i:42;}}
# Check the result by piping into PHP and unserializing the result.
$ ./bin/cake ConfigRead.ConfigRead -s Key.Name Second.Key | php -r 'print_r(unserialize(file_get_contents("php://stdin")));'
Array
(
    [Key.Name] => foo

    [Second.Key] => Array
        (
            [First] => bar
            [Second] => baz
            [Third] => 42
        )

)

Potential Gotchas

"Consumed" Configure Vars

CakePHP 3 by default "consumes" some of its configs so as not to confuse developers. Configure::consume() removes the configuration key from Configure, making it unavailable to the rest of the app. At the time of this writing, it does this for the following keys/classes:, (*11)

[Configure.Key] Class::configEnumerationMethod() Class::configFetchMethod()
[Cache] Cache::configured() Cache::getConfig()
[Datasources] ConnectionManager::configured() ConnectionManager::getConfig()
[EmailTransport] Email::configuredTransport() Email::getConfigTransport()
[Email] Email::configured() Email::getConfig()
[Log] Log::configured() Log::getConfig()
[Security.salt] (none) Security::getSalt()

The ConfigReadShell devotes about half of its codebase dealing with this for you, allowing you to continue to fetch values using the Configure path (Datasources.default.host -> localhost) while in the background it is actually querying ConnectionManager::getConfig('default')['host']. (This is particularly helpful if you are using Environment-Aware Configs.), (*12)

The "gotcha" here is that ConfigReadShell has to maintain a hard-coded list of Configure keys that are normally consumed, and how to access them in their new container. This is further complicated by the fact that not all consumed configs are loaded into or retrieved from their containers the same way, although the base assumption is that the container implements the StaticConfigTrait and so will have ::getConfig() and ::configured() available., (*13)

:warning: If your app uses Configure::consume() on any non-standard Configure key during bootstrapping, you will not be able to obtain any child values of those keys from the ConfigReadShell., (*14)

Contributing

Code of Conduct

This project has adopted the Contributor Covenant as its code of conduct. All contributors are expected to adhere to this code. Translations are available., (*15)

Reporting Issues

Please use GitHub Isuses for listing any known defects or issues., (*16)

Development

When developing this plugin, please fork and issue a PR for any new development., (*17)

License

MIT, (*18)

Loadsys Web Strategies 2018, (*19)

The Versions

03/10 2016

dev-master

9999999-dev https://github.com/loadsys/CakePHP-ConfigReadShell

A CakePHP plugin that provides a Shell to read an app's Configure vars from the command line.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Brian Porter

cakephp shell configure

03/10 2016

3.3.1

3.3.1.0 https://github.com/loadsys/CakePHP-ConfigReadShell

A CakePHP plugin that provides a Shell to read an app's Configure vars from the command line.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Brian Porter

cakephp shell configure

24/06 2016

3.3.0

3.3.0.0 https://github.com/loadsys/CakePHP-ConfigReadShell

A CakePHP plugin that provides a Shell to read an app's Configure vars from the command line.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Brian Porter

cakephp shell configure

08/07 2015

3.2.0

3.2.0.0 https://github.com/loadsys/CakePHP-ConfigReadShell

A CakePHP plugin that provides a Shell to read an app's Configure vars from the command line.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Brian Porter

cakephp shell configure

06/07 2015

3.1.2

3.1.2.0 https://github.com/loadsys/CakePHP-ConfigReadShell

A CakePHP plugin that provides a Shell to read an app's Configure vars from the command line.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Brian Porter

cakephp shell configure

15/06 2015

3.1.1

3.1.1.0 https://github.com/loadsys/CakePHP-ConfigReadShell

A CakePHP plugin that provides a Shell to read an app's Configure vars from the command line.

  Sources   Download

MIT

The Requires

 

by Brian Porter

cakephp shell configure

15/06 2015

dev-cake-2.x

dev-cake-2.x https://github.com/loadsys/CakePHP-ConfigReadShell

A CakePHP plugin that provides a Shell to read an app's Configure vars from the command line.

  Sources   Download

MIT

The Requires

 

by Brian Porter

cakephp shell configure

15/06 2015

2.1.1

2.1.1.0 https://github.com/loadsys/CakePHP-ConfigReadShell

A CakePHP plugin that provides a Shell to read an app's Configure vars from the command line.

  Sources   Download

MIT

The Requires

 

by Brian Porter

cakephp shell configure

14/04 2015

2.1.0

2.1.0.0 https://github.com/loadsys/CakePHP-ConfigReadShell

A CakePHP plugin that provides a Shell to read an app's Configure vars from the command line.

  Sources   Download

MIT

The Requires

 

by Brian Porter

cakephp shell configure

14/04 2015

3.1.0

3.1.0.0 https://github.com/loadsys/CakePHP-ConfigReadShell

A CakePHP plugin that provides a Shell to read an app's Configure vars from the command line.

  Sources   Download

MIT

The Requires

 

by Brian Porter

cakephp shell configure

08/04 2015

3.0.2

3.0.2.0 https://github.com/loadsys/CakePHP-ConfigReadShell

A CakePHP plugin that provides a Shell to read an app's Configure vars from the command line.

  Sources   Download

MIT

The Requires

 

by Brian Porter

cakephp shell configure

06/04 2015

dev-f/travis-builds

dev-f/travis-builds https://github.com/loadsys/CakePHP-ConfigReadShell

A CakePHP plugin that provides a Shell to read an app's Configure vars from the command line.

  Sources   Download

MIT

The Requires

 

by Brian Porter

cakephp shell configure

02/04 2015

3.0.1

3.0.1.0 https://github.com/loadsys/CakePHP-ConfigReadShell

A CakePHP plugin that provides a Shell to read an app's Configure vars from the command line.

  Sources   Download

MIT

The Requires

 

by Brian Porter

cakephp shell configure

02/04 2015

3.0.0

3.0.0.0 https://github.com/loadsys/CakePHP-ConfigReadShell

A CakePHP plugin that provides a Shell to read an app's Configure vars from the command line.

  Sources   Download

MIT

The Requires

 

by Brian Porter

cakephp shell configure

25/02 2015

2.0.1

2.0.1.0 https://github.com/loadsys/CakePHP-ConfigReadShell

A CakePHP plugin that provides a Shell to read an app's Configure vars from the command line.

  Sources   Download

MIT

The Requires

 

by Brian Porter

cakephp shell configure

25/02 2015

dev-cake-1.3

dev-cake-1.3 https://github.com/loadsys/CakePHP-ConfigReadShell

A CakePHP plugin that provides a Shell to read an app's Configure vars from the command line.

  Sources   Download

MIT

The Requires

 

by Brian Porter

cakephp shell configure

25/02 2015

1.0.1

1.0.1.0 https://github.com/loadsys/CakePHP-ConfigReadShell

A CakePHP plugin that provides a Shell to read an app's Configure vars from the command line.

  Sources   Download

MIT

The Requires

 

by Brian Porter

cakephp shell configure

03/02 2015

dev-f/updated-composer-installation

dev-f/updated-composer-installation https://github.com/loadsys/CakePHP-ConfigReadShell

A CakePHP plugin that provides a Shell to read an app's Configure vars from the command line.

  Sources   Download

MIT

The Requires

 

by Brian Porter

cakephp shell configure

06/01 2015

2.0.0

2.0.0.0 https://github.com/loadsys/CakePHP-ConfigReadShell

A CakePHP plugin that provides a Shell to read an app's Configure vars from the command line.

  Sources   Download

MIT

The Requires

 

by Brian Porter

cakephp shell configure

06/01 2015

1.0.0

1.0.0.0 https://github.com/loadsys/CakePHP-ConfigReadShell

A CakePHP plugin that provides a Shell to read an app's Configure vars from the command line.

  Sources   Download

MIT

The Requires

 

by Brian Porter

cakephp shell configure