Skip to content

Commit 36ccdc5

Browse files
committed
Wrote a rough readme spec for --serialize operation.
1 parent ea130f8 commit 36ccdc5

1 file changed

Lines changed: 49 additions & 1 deletion

File tree

README.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,26 @@ $ composer require loadsys/cakephp-config-read:~3.0
2828

2929
## Usage
3030

31+
Imagine the following defined in `config/app.php`:
32+
33+
```php
34+
return [
35+
'Key' => [
36+
'Name' => 'foo',
37+
],
38+
'Second' => [
39+
'Key' => [
40+
'First' => 'bar',
41+
'Second' => 'baz',
42+
'Third' => 42,
43+
],
44+
],
45+
];
46+
```
47+
48+
49+
To use this plugin, call it from the command line:
50+
3151
```shell
3252
$ cd path/to/app/
3353
$ ./bin/cake ConfigRead Key.Name
@@ -44,13 +64,41 @@ SECOND_KEY_SECOND='baz'
4464
SECOND_KEY_THIRD='42'
4565
```
4666

47-
Note that this format is automatically used whenever more than one key is returned. 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 be returned. The format can also be forced using the `-b` or `--bash` command line switch:
67+
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:
4868

4969
```shell
5070
$ ./bin/cake ConfigRead -b Key.Name
5171
KEY_NAME='foo'
5272
```
5373

74+
### Serializing output
75+
76+
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.
77+
78+
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.
79+
80+
This switch always overrides both the `--bash` switch and the Shell's automatic bash formatting.
81+
82+
```shell
83+
$ ./bin/cake ConfigRead -s Key.Name Second.Key
84+
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;}}
85+
# Check the result by piping into PHP and unserializing the result.
86+
$ ./bin/cake ConfigRead -s Key.Name Second.Key | php -r 'print_r(unserialize(file_get_contents("php://stdin")));'
87+
Array
88+
(
89+
[Key.Name] => foo
90+
91+
[Second.Key] => Array
92+
(
93+
[First] => bar
94+
[Second] => baz
95+
[Third] => 42
96+
)
97+
98+
)
99+
```
100+
101+
54102
## Gotchas
55103

56104
### "Consumed" Configure Vars

0 commit comments

Comments
 (0)