|
1 | 1 | # CakePHP-ConfigReadShell |
2 | 2 |
|
3 | 3 | [](https://github.com/loadsys/CakePHP-ConfigReadShell/releases) |
| 4 | +[](https://travis-ci.org/loadsys/CakePHP-ConfigReadShell) |
| 5 | +[](https://coveralls.io/r/loadsys/CakePHP-ConfigReadShell?branch=master) |
4 | 6 | [](LICENSE.md) |
5 | 7 | [](https://packagist.org/packages/loadsys/cakephp-config-read) |
6 | 8 |
|
7 | 9 | A CakePHP plugin that provides a Shell to read an app's Configure vars from the command line. |
8 | 10 |
|
9 | | - |
10 | | -* This is the Cake 3.x version of the plugin, which exists on the `master` branch and is tracked by the `3.*` semver. |
11 | | -* For the Cake 2.x version of this plugin, please use the repo's `cake-2.x` branch. (semver `2.*`) |
12 | | -* For the Cake 1.3 version, use the `cake-1.3` branch. (semver `1.*`) **Note:** we don't expect to actively maintain the 1.3 version. It's here because the project started life as a 1.3 Shell. |
| 11 | +* This is the Cake 3.x version of the plugin, which exists on the `master` branch and is tracked by the `~3.0` semver. |
| 12 | +* For the Cake 2.x version of this plugin, please use the repo's `cake-2.x` branch. (semver `~2.0`) |
| 13 | +* For the Cake 1.3 version, use the `cake-1.3` branch. (semver `~1.0`) **Note:** we don't expect to actively maintain the 1.3 version. It's here because the project started life as a 1.3 Shell. |
13 | 14 |
|
14 | 15 |
|
15 | 16 | ## Requirements |
16 | 17 |
|
17 | 18 | * CakePHP 3.0.0+ |
18 | | -* PHP 5.4.19+ |
| 19 | +* PHP 5.6+ |
19 | 20 |
|
20 | 21 |
|
21 | 22 | ## Installation |
@@ -50,6 +51,62 @@ $ ./bin/cake ConfigRead -b Key.Name |
50 | 51 | KEY_NAME='foo' |
51 | 52 | ``` |
52 | 53 |
|
| 54 | +## Gotchas |
| 55 | + |
| 56 | +### "Consumed" Configure Vars |
| 57 | + |
| 58 | +CakePHP 3 by default "consumes" some of its configs so as not to confused developers. [`Configure::consume()`](http://book.cakephp.org/3.0/en/development/configuration.html#Cake\Core\Configure::consume) removes the configuration key from Configure, making it unavailable to the rest of the app. At the [time of this writing](https://github.com/cakephp/app/blob/a0f2c4/config/bootstrap.php#L136,L141), it does this for the following keys/classes: |
| 59 | + |
| 60 | +* Cache/Cache |
| 61 | +* Datasources/ConnectionManager |
| 62 | +* EmailTransport/Email |
| 63 | +* Email/Email |
| 64 | +* Log/Log |
| 65 | +* Security.salt/Security::salt() |
| 66 | + |
| 67 | +The effect is that you can not use the ConfigReadShell to obtain Configure values for any of these keys since they no longer exist in Configure's store. (This is particularly troublesome if you are using [Environment-Aware Configs](https://github.com/beporter/CakePHP-EnvAwareness/tree/master/slides).) |
| 68 | + |
| 69 | +There are two possible workarounds: |
| 70 | + |
| 71 | +1. Use the `ConsoleShell` instead. For example: |
| 72 | + |
| 73 | + ```shell |
| 74 | + $ echo 'use Cake\Datasource\ConnectionManager; foreach(ConnectionManager::config("default") as $k => $v) { echo "$k=" . escapeshellarg($v) . PHP_EOL; } exit;' | bin/cake Console -q |
| 75 | + className='Cake\Database\Connection' |
| 76 | + driver='Cake\Database\Driver\Mysql' |
| 77 | + persistent='' |
| 78 | + host='localhost' |
| 79 | + username='my_app' |
| 80 | + password='secret' |
| 81 | + database='my_app' |
| 82 | + encoding='utf8' |
| 83 | + timezone='UTC' |
| 84 | + cacheMetadata='1' |
| 85 | + quoteIdentifiers='' |
| 86 | + name='default' |
| 87 | + ``` |
| 88 | + |
| 89 | + This command is wrapped up in our [loadsys/cakephp-shell-scripts](https://github.com/loadsys/CakePHP-Shell-Scripts) repo as the [`db-credentials`](https://github.com/loadsys/CakePHP-Shell-Scripts/blob/76a24/db-credentials) script. |
| 90 | + |
| 91 | +2. Edit your `config/bootstrap.php` to use `Configure::read()` instead of `Configure::consume()`. |
| 92 | + |
| 93 | + ```diff |
| 94 | + -Cache::config(Configure::consume('Cache')); |
| 95 | + -ConnectionManager::config(Configure::consume('Datasources')); |
| 96 | + -Email::configTransport(Configure::consume('EmailTransport')); |
| 97 | + -Email::config(Configure::consume('Email')); |
| 98 | + -Log::config(Configure::consume('Log')); |
| 99 | + -Security::salt(Configure::consume('Security.salt')); |
| 100 | + +Cache::config(Configure::read('Cache')); |
| 101 | + +ConnectionManager::config(Configure::read('Datasources')); |
| 102 | + +Email::configTransport(Configure::read('EmailTransport')); |
| 103 | + +Email::config(Configure::read('Email')); |
| 104 | + +Log::config(Configure::read('Log')); |
| 105 | + +Security::salt(Configure::read('Security.salt')); |
| 106 | + ``` |
| 107 | + |
| 108 | + This will leave the Configure vars in place and allow commands like `bin/cake ConfigRead Datasources.default` to work as expected, but be warned that the values in Configure might not reflect the values actually being used by the various Cake modules. |
| 109 | + |
53 | 110 |
|
54 | 111 | ## Contributing |
55 | 112 |
|
|
0 commit comments