Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit ae9c92c

Browse files
committed
Merge branch 'feature/61' into develop
Forward port #61
2 parents 93b69ea + 7e9d21c commit ae9c92c

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

docs/book/processor.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ This example returns the output: `bar`. The filters in the queue are applied in
124124
This example illustrates basic usage of `Zend\Config\Processor\Token`:
125125

126126
```php
127+
use Zend\Config\Config;
128+
use Zend\Config\Processor\Token as TokenProcessor;
129+
127130
// Provide the second parameter as boolean true to allow modifications:
128131
$config = new Config(['foo' => 'Value is TOKEN'], true);
129132
$processor = new TokenProcessor();
@@ -136,7 +139,7 @@ echo $config->foo;
136139

137140
This example returns the output: `Value is TOKEN,Value is bar`.
138141

139-
As of version 3.1.0, you can also tell the `Constant` processor to process keys:
142+
As of version 3.1.0, you can also tell the `Token` processor to process keys:
140143

141144
```php
142145
// At instantiation:
@@ -148,6 +151,44 @@ $processor->enableKeyProcessing();
148151

149152
When enabled, any token values found in keys will also be replaced.
150153

154+
### Using Token processor as a simple environment processor
155+
156+
Token processor can be utilized to populate config values using common
157+
format `%env(ENV_VAR)%` with values from environment by setting Token
158+
processor `$prefix` and `$suffix` parameters to `%env(` and `)%` respectively:
159+
160+
```php
161+
use Zend\Config\Config;
162+
use Zend\Config\Processor\Token as TokenProcessor;
163+
164+
putenv('AMQP_PASSWORD=guest');
165+
166+
// Populate list if tokens to replace from environment:
167+
$processor = new TokenProcessor(getenv(), '%env(', ')%');
168+
169+
// Provide the second parameter as boolean true to allow modifications:
170+
$config = new Config([
171+
'host' => '127.0.0.1',
172+
'port' => 5672,
173+
'username' => '%env(AMQP_USER)%',
174+
'password' => '%env(AMQP_PASSWORD)%',
175+
'vhost' => '/',
176+
], true);
177+
178+
$processor->process($config);
179+
print_r($config->toArray());
180+
// Array
181+
// (
182+
// [host] => 127.0.0.1
183+
// [port] => 5672
184+
// [username] => %env(AMQP_USER)%
185+
// [password] => guest
186+
// [vhost] => /
187+
// )
188+
```
189+
Do note, however, that only values present in environment will be replaced.
190+
This allows multiple fallback processors to be provided as a queue.
191+
151192
## Zend\\Config\\Processor\\Translator
152193

153194
### Using Zend\\Config\\Processor\\Translator

0 commit comments

Comments
 (0)