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

Commit 4090ddb

Browse files
committed
Merge branch 'hotfix/7'
Close #7
2 parents 1f6195f + 5e470b1 commit 4090ddb

File tree

10 files changed

+373
-208
lines changed

10 files changed

+373
-208
lines changed

.travis.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@ language: php
55
cache:
66
directories:
77
- $HOME/.composer/cache
8+
- $HOME/.local
89
- vendor
10+
- zf-mkdoc-theme
911

1012
env:
1113
global:
1214
- COMPOSER_ARGS="--no-interaction"
1315
- COVERAGE_DEPS="satooshi/php-coveralls"
16+
- SITE_URL=https://docs.zendframework.com/zend-config-aggregator
17+
- GH_USER_NAME="Matthew Weier O'Phinney"
18+
- GH_USER_EMAIL=matthew@weierophinney.net
19+
- GH_REF=github.com/zendframework/zend-config-aggregator.git
20+
- secure: "dN904HglCkMIRYDWuG954EDSIq8w4IhhDgfN5PasYudyM56f8dRACIfdn6hwy2Bcp3DUkd21FMjKbnIiTG+FfmquN7VmL3ZMeo6xuMZn2FMDhzHKHq0aM1NMFA+NpPPOpVD2kZDrjpNq99PGolX2KEU/JQn3nAO/2y7yRMLVfGydLGcOkT+LdOzxpfA+RDrAf3WBUv+7zbokHHfVvUwhY+kbX8abMS9seDBsqootA48lLNl433y24a3M4P/Bw2F3KdXriVeApkZ4jPCTOSyYqhyDsU0KJrSpRpOOFnkP+R8kSRGkpuiWxibGSy4yUP4v/ocp/tLptU5xnIlI4jdWXQifbMX/2bs2bkVXtRVH6Eb+G3BwPjqgbDXf6igSlbktTQBAxnoG0WPEMlNkxQBYgbMXZwoODNAyYw/Ziyi0l1fQiWUQe9FjwQZpawuJU0c7mqDHWC+qjo50NNeq0xaSZ6etuOcdmPQpdCDqHbnVzaNdQCdYIAEg502xjumacLIzYhcGGUq7le/hsnyzILzlY1EOxghATdWg2Z6ly/7Ul2TqfNt3A5sRoJQucbfovJfsNQjxyjlEjcOxJyICBFZXFsW3PRYglg6AMuojHC3H28Fo7adZtmWMw68dzyZtfmra5h935/B/ghZi+cItxMgx07/EsBLsbBFsoMZkwvCIQYo="
1421

1522
matrix:
1623
fast_finish: false
@@ -23,6 +30,7 @@ matrix:
2330
- DEPS=locked
2431
- TEST_COVERAGE=true
2532
- PATH="$HOME/.local/bin:$PATH"
33+
- DEPLOY_DOCS="$(if [[ $TRAVIS_BRANCH == 'master' && $TRAVIS_PULL_REQUEST == 'false' ]]; then echo -n 'true' ; else echo -n 'false' ; fi)"
2634
- php: 5.6
2735
env:
2836
- DEPS=latest
@@ -73,10 +81,18 @@ script:
7381
- if [[ $TEST_COVERAGE == 'true' ]]; then composer test-coverage ; else composer test ; fi
7482
- if [[ $CS_CHECK == 'true' ]]; then composer cs-check ; fi
7583
- if [[ $CS_CHECK == 'true' ]]; then composer license-check ; fi
84+
- if [[ $DEPLOY_DOCS == "true" && "$TRAVIS_TEST_RESULT" == "0" ]]; then wget -O theme-installer.sh "https://raw.githubusercontent.com/zendframework/zf-mkdoc-theme/master/theme-installer.sh" ; chmod 755 theme-installer.sh ; ./theme-installer.sh ; fi
7685

7786
after_script:
7887
- if [[ $TEST_COVERAGE == 'true' ]]; then composer upload-coverage ; fi
7988

89+
after_success:
90+
- if [[ $DEPLOY_DOCS == "true" ]]; then echo "Preparing to build and deploy documentation" ; ./zf-mkdoc-theme/deploy.sh ; echo "Completed deploying documentation" ; fi
91+
8092
notifications:
81-
irc: "irc.freenode.org#zftalk.dev"
8293
email: false
94+
slack:
95+
rooms:
96+
- secure: "ZvwOGYOX2UzaLI9OXvpsJeFybUj3MjYPS2lJC1VVKYlDw7Lv8+ruiqb/Ku5VO26AuSjEmkVy6MDWj4mklXRRVpEie1BrjTe/o+m/4TH/8/ngYF5QaNlBppUOeSTHzkFmN0k7UvcG99tDMwIszVNtMy2ASox5JQYCkfOgzWGhgtgdmYvCOyKh50875roG8PGfIEk1Jqb2ANgcUaoZJFhRHmsW0xtSUiu4WiI8psARG56n50b0grQHhb9TztcQomQTyYQUxzD5Ft/tsSm0TKTW3Nxf/TvAtyY81bTzPq0Y8vtypYDmFVR8WQTI1AeKJLfbrerRpdfFvHDSL8BGo50y2MVa8Zr8imxpzpC23Sx464TAdABuufbJl7qlg+4UPwJxFQAy9TPzXg20UwP3TT0Fim60aiLcRkMpI4i5z+AGoX/Gz+Y5RJ6TWsidXPc1Gjuf/1j3HV3OlyiZGJ1xq5HgvNFgSKkEnYgejDYXvWa+RGhYIw11pipFLccuBV4GcjXwRVctc9ExcDIen9lfjX+p7eUpYaDqsq6CBDjFBW7K03LfbhrB8sQLoP24QGPBH5IzkFn5t08GVhuJV3Z4pDj7CLi3TcwIF8n8qKRuVQ+ezRwV6DlJbTCfU5swUVrzWJrqybBgC0kZP9RKPPp1FUuoke5THMkQUdQYb/93x1oKnio="
97+
on_success: change
98+
on_failure: always

CHANGELOG.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,44 @@
22

33
All notable changes to this project will be documented in this file, in reverse chronological order by release.
44

5+
## 1.0.0 - TBD
6+
7+
### Added
8+
9+
- [#7](https://github.com/zendframework/zend-config-aggregator/pull/7) adds
10+
online documentation at https://docs.zendframework.com/zend-config-aggregator/
11+
12+
### Deprecated
13+
14+
- Nothing.
15+
16+
### Removed
17+
18+
- Nothing.
19+
20+
### Fixed
21+
22+
- Nothing.
23+
24+
## 0.2.1 - 2017-04-23
25+
26+
### Added
27+
28+
- [#3](https://github.com/zendframework/zend-config-aggregator/pull/3) added
29+
zend-config ^3.0 support
30+
31+
### Deprecated
32+
33+
- Nothing.
34+
35+
### Removed
36+
37+
- Nothing.
38+
39+
### Fixed
40+
41+
- Nothing.
42+
543
## 0.2.0 - 2017-01-11
644

745
### Added

README.md

Lines changed: 14 additions & 206 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,14 @@
11
# zend-config-aggregator
22

3-
[![Build Status](https://travis-ci.org/zendframework/zend-config-aggregator.svg?branch=master)](https://travis-ci.org/zendframework/zend-config-aggregator)
3+
[![Build Status](https://travis-ci.org/zendframework/zend-config-aggregator.svg?branch=master)](https://travis-ci.org/zendframework/zend-config-aggregator)
44

5-
(Based on [mtymek/expressive-config-manager](https://github.com/mtymek/expressive-config-manager).)
6-
7-
Lightweight library for collecting and merging configuration from different sources.
8-
9-
While designed for [Expressive](https://github.com/zendframework/zend-expressive)
10-
applications, it can work with any PHP project for aggregating and returning
11-
merged configuration, from either a variety of configuration formats or
12-
"configuration providers", invokable classes returning an array of configuration
13-
(or a PHP generator). It also supports configuration caching.
5+
Aggregates and merges configuration, from a variety of formats. Supports caching
6+
for fast bootstrap in production environments.
147

158
## Usage
169

17-
### Config files
18-
19-
At the basic level, `ConfigAggregator` can be used to merge PHP-based
20-
configuration files:
10+
The standalone `ConfigAggregator` can be used to merge PHP-based configuration
11+
files:
2112

2213
```php
2314
use Zend\ConfigAggregator\ConfigAggregator;
@@ -68,204 +59,21 @@ array(3) {
6859
Configuration is merged in the same order as it is passed, with later entries
6960
having precedence.
7061

71-
### Config providers
72-
73-
`ConfigAggregator` works by aggregating "Config Providers" passed to its
74-
constructor. Each provider should be a callable, returning a configuration
75-
array (or a PHP generator) to be merged.
76-
77-
```php
78-
$aggregator = new ConfigAggregator([
79-
function () {
80-
return ['foo' => 'bar'];
81-
},
82-
new PhpFileProvider('*.global.php'),
83-
]);
84-
var_dump($aggregator->getMergedConfig());
85-
```
86-
87-
If the provider is a class name, the aggregator automatically instantiates it.
88-
This can be used to mimic the Zend Framework module system: you can specify a
89-
list of config providers from different packages, and aggregated configuration
90-
will be available to your application.
91-
92-
As a library owner, you can distribute your own configuration providers that
93-
provide default values for use with your library.
94-
95-
As an example:
96-
97-
```php
98-
class ApplicationConfig
99-
{
100-
public function __invoke()
101-
{
102-
return ['foo' => 'bar'];
103-
}
104-
}
105-
106-
$aggregator = new ConfigAggregator(
107-
[
108-
ApplicationConfig::class,
109-
new PhpFileProvider('*.global.php'),
110-
]
111-
);
112-
var_dump($configManager->getMergedConfig());
113-
```
114-
115-
Output from both examples will be the same:
116-
117-
```php
118-
array(4) {
119-
'foo' =>
120-
string(3) "bar"
121-
'db' =>
122-
array(1) {
123-
'dsn' =>
124-
string(9) "mysql:..."
125-
}
126-
'cache_storage' =>
127-
string(5) "redis"
128-
'redis' =>
129-
array(0) {
130-
}
131-
}
132-
```
133-
134-
### Caching
135-
136-
Merging configuration on every request is not performant. As such,
137-
zend-config-aggregator also provides the ability to enable a filesystem-based
138-
configuration cache.
139-
140-
To enable the configuration cache, pass a cache file name as the second
141-
parameter to the `ConfigAggregator` constructor:
142-
143-
```php
144-
$aggrgator = new ConfigAggregator(
145-
[
146-
function () { return [ConfigAggregator::ENABLE_CACHE => true]; },
147-
new PhpFileProvider('*.global.php'),
148-
],
149-
'data/config-cache.php'
150-
);
151-
```
152-
153-
When a cache file is specified, you will also need to add the
154-
`config_cache_enabled` key (which you can also specify via the
155-
`ConfigAggregator::ENABLE_CACHE` constant) somewhere within one of your
156-
configuration providers, and set it to boolean `true`. Using this approach, if
157-
you were to use the globbing pattern `{{,*.}global,{,*.}local}.php` (or similar)
158-
with the `PhpFileProvider`, you could drop a file named `enable-cache.local.php`
159-
into your production deployment with the following contents in order to enable
160-
configuration caching in production:
161-
162-
```php
163-
<?php
164-
use Zend\ConfigAggregator\ConfigAggregator;
165-
166-
return [
167-
ConfigAggregator::ENABLE_CACHE => true,
168-
];
169-
```
170-
171-
When caching is enabled, the `ConfigAggregator` does not iterate config
172-
providers. Because of that it is very fast, but after it is enabled you cannot
173-
make any changes to configuration without clearing the cache. **Caching should
174-
be used only in a production environment**, and your deployment process should
175-
clear the cache.
176-
177-
### Generators
178-
179-
Config providers can be written as generators. This way single callable can provide
180-
multiple configurations:
181-
182-
```php
183-
use Zend\ConfigAggregator\ConfigAggregator;
184-
use Zend\Stdlib\Glob;
185-
186-
$aggregator = new ConfigAggregator([
187-
function () {
188-
foreach (Glob::glob('data/*.global.php', Glob::GLOB_BRACE) as $file) {
189-
yield include $file;
190-
}
191-
}
192-
]
193-
);
194-
var_dump($aggregator->getMergedConfig());
195-
```
196-
197-
The providers `PhpFileProvider` is implemented using generators.
198-
199-
200-
## Available config providers
201-
202-
### PhpFileProvider
203-
204-
Loads configuration from PHP files returning arrays, such as this one:
205-
206-
```php
207-
return [
208-
'db' => [
209-
'dsn' => 'mysql:...',
210-
],
211-
];
212-
```
213-
214-
Wildcards are supported:
215-
216-
```php
217-
use Zend\ConfigAggregator\ConfigAggregator;
218-
use Zend\ConfigAggregator\PhpFileProvider;
219-
220-
$aggregator = new ConfigAggregator(
221-
[
222-
new PhpFileProvider('config/*.global.php'),
223-
]
224-
);
225-
```
226-
227-
The example above will merge all matching files from the `config/` directory. If
228-
you have files such as `app.global.php` or `database.global.php` in that
229-
directory, they will be loaded using this above lines of code.
230-
231-
Globbing defaults to PHP's `glob()` function. However, if `Zend\Stdlib\Glob` is
232-
available, it will use that to allow for cross-platform glob patterns, including
233-
brace notation: `'config/autoload/{{,*.}global,{,*.}local}.php'`. Install
234-
zendframework/zend-stdlib to utilize this feature.
235-
236-
### ZendConfigProvider
237-
238-
Sometimes using plain PHP files may be not enough; you may want to build your configuration
239-
from multiple files of different formats, such as INI, YAML, or XML.
240-
zend-config-aggregator allows you to do so via its `ZendConfigProvider`:
62+
Together with `zend-config`, `zend-config-aggregator` can be also used to load
63+
configuration in different formats, including YAML, JSON, XML, or INI:
24164

24265
```php
24366
use Zend\ConfigAggregator\ConfigAggregator;
24467
use Zend\ConfigAggregator\ZendConfigProvider;
24568

246-
$aggregator = new ConfigAggregator(
247-
[
248-
new ZendConfigProvider('*.global.json'),
249-
new ZendConfigProvider('database.local.ini'),
250-
]
251-
);
69+
$aggregator = new ConfigAggregator([
70+
new ZendConfigProvider('config/*.{json,yaml,php}'),
71+
]);
25272
```
25373

254-
These could even be combined into a single glob statement:
255-
256-
```php
257-
$aggregator = new ConfigAggregator(
258-
[
259-
new ZendConfigProvider('*.global.json,database.local.ini'),
260-
]
261-
);
262-
```
74+
For more details, please refer to the [documentation](https://docs.zendframework.com/zend-config-aggregator/).
26375

264-
`ZendConfigProvider` accepts wildcards and autodetects the config type based on
265-
file extension.
76+
-----
26677

267-
ZendConfigProvider requires two packages to be installed:
268-
`zendframework/zend-config` and `zendframework/zend-servicemanager`. Some config
269-
readers (JSON, YAML) may need additional dependencies; please refer to
270-
[the zend-config manual](https://docs.zendframework.com/zend-config/reader/)
271-
for more details.
78+
- File issues at https://github.com/zendframework/zend-config-aggregator/issues
79+
- Documentation is at https://docs.zendframework.com/zend-config-aggregator/

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"require-dev": {
1616
"phpunit/phpunit": "^5.7",
1717
"zendframework/zend-coding-standard": "~1.0.0",
18-
"zendframework/zend-config": "^2.6",
18+
"zendframework/zend-config": "^2.6 || ^3.0",
1919
"zendframework/zend-servicemanager": "^2.7.7 || ^3.1.1",
2020
"malukenho/docheader": "^0.1.5",
2121
"mikey179/vfsStream": "^1.6"

doc/book/caching.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Caching
2+
3+
Merging configuration on every request is not performant, particularly when
4+
using many configuration files. As such, zend-config-aggregator also
5+
provides the ability to enable a filesystem-based configuration cache.
6+
7+
To enable the configuration cache, pass a cache file name as the second
8+
parameter to the `ConfigAggregator` constructor:
9+
10+
```php
11+
use Zend\ConfigAggregator\ArrayProvider;
12+
use Zend\ConfigAggregator\ConfigAggregator;
13+
use Zend\ConfigAggregator\PhpFileProvider;
14+
15+
$aggregator = new ConfigAggregator(
16+
[
17+
new ArrayProvider([ConfigAggregator::ENABLE_CACHE => true]),
18+
new PhpFileProvider('*.global.php'),
19+
],
20+
'data/config-cache.php'
21+
);
22+
```
23+
24+
When a cache file is specified, you will also need to add the
25+
`config_cache_enabled` key (which you can also specify via the
26+
`ConfigAggregator::ENABLE_CACHE` constant) somewhere within one of your
27+
configuration providers, and set it to boolean `true`. Using this approach, if
28+
you were to use the globbing pattern `{{,*.}global,{,*.}local}.php` (or similar)
29+
with the `PhpFileProvider`, you could drop a file named `enable-cache.local.php`
30+
into your production deployment with the following contents in order to enable
31+
configuration caching in production:
32+
33+
```php
34+
<?php
35+
use Zend\ConfigAggregator\ConfigAggregator;
36+
37+
return [
38+
ConfigAggregator::ENABLE_CACHE => true,
39+
];
40+
```
41+
42+
When caching is enabled, the `ConfigAggregator` does not iterate config
43+
providers. Because of that it is very fast, but after it is enabled, you cannot
44+
make any changes to configuration without clearing the cache. **Caching should
45+
be used only in a production environment**, and your deployment process should
46+
clear the cache.

0 commit comments

Comments
 (0)