Skip to content

Commit 74fc934

Browse files
committed
Merge remote-tracking branch 'origin/hotfix/inconsistency-default-options'
2 parents f60e477 + 5511eb4 commit 74fc934

13 files changed

Lines changed: 327 additions & 52 deletions

CHANGELOG.md

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

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

5+
## 2.0.1 (2016-12-09)
6+
This release contains **no** BC break.
7+
8+
### Added
9+
10+
* More test cases for iterable return type and `\Iterator` objects
11+
12+
### Deprecated
13+
14+
* Nothing
15+
16+
### Removed
17+
18+
* Nothing
19+
20+
### Fixed
21+
22+
* [#34](https://github.com/sandrokeil/interop-config/issue/34): Inconsistent return type in `defaultOptions()`
23+
* `defaultOptions()` method return type is `iterable` but `array` is still valid
24+
25+
526
## 2.0.0 (2016-12-06)
627
To upgrade from version 1.x to version 2.x you have to add the PHP scalar types of the interfaces to your implemented
728
factory methods.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ You should have coding conventions and you should have config conventions. If no
3838

3939
## Installation
4040

41-
Installation of this module uses composer. For composer documentation, please refer to
41+
The suggested installation method is via composer. For composer documentation, please refer to
4242
[getcomposer.org](http://getcomposer.org/).
4343

4444
Run `composer require sandrokeil/interop-config` to install interop-config. Version `1.x` is for PHP < 7.1 and Version `2.x` is for PHP >= 7.1.

doc/book/intro.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ You should have coding conventions and you should have config conventions. If no
3636
`interop-config` is universally applicable! See further documentation for more details.
3737

3838
## Installation
39-
Installation of this library uses Composer. For Composer documentation, please refer to
39+
The suggested installation method is via composer. For composer documentation, please refer to
4040
[getcomposer.org](http://getcomposer.org/).
4141

4242
Run `composer require sandrokeil/interop-config` to install interop-config.

doc/book/quick-start.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ class MyAwesomeFactory implements RequiresConfigId
3939
public function dimensions() : iterable
4040
{
4141
return ['vendor-package'];
42-
}
43-
44-
public function canRetrieveOptions($config, $configId = null) : bool
42+
}
43+
44+
public function canRetrieveOptions($config, string $configId = null) : bool
4545
{
4646
// custom implementation depending on specifications
4747
}
4848

49-
public function options($config, $configId = null)
49+
public function options($config, string $configId = null)
5050
{
5151
// custom implementation depending on specifications
5252
}

doc/bookdown.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"title": "interop-config",
2+
"title": "interop-config - configurable factories",
33
"content": [
44
{"getting-started": "book/getting-started/bookdown.json"},
55
{"reference": "book/reference/bookdown.json"},
@@ -8,5 +8,5 @@
88
"target": "./html",
99
"tocDepth": 2,
1010
"template": "../vendor/tobiju/bookdown-bootswatch-templates/templates/main.php",
11-
"copyright": "Copyright (c) 2015-2016 <a href=\"https://sandro-keil.de/\" title=\"I write about topics, advices and trends of web development\">Sandro Keil</a> <br/> Powered by <a href=\"https://github.com/tobiju/bookdown-bootswatch-templates\" title=\"Visit project to generate your own docs\">Bookdown Bootswatch Templates</a>"
11+
"copyright": "Visit interop-config on <a href=\"https://github.com/sandrokeil/interop-config\" title=\"interop-config on GitHub\">GitHub</a><br/>Copyright (c) 2015-2016 <a href=\"https://sandro-keil.de/\" title=\"I write about topics, advices and trends of web development\">Sandro Keil</a> <br/> Powered by <a href=\"https://github.com/tobiju/bookdown-bootswatch-templates\" title=\"Visit project to generate your own docs\">Bookdown Bootswatch Templates</a>"
1212
}

src/ConfigurationTrait.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use ArrayAccess;
1515
use Interop\Config\Exception;
16+
use Iterator;
1617

1718
/**
1819
* ConfigurationTrait which retrieves options from configuration, see interface \Interop\Config\RequiresConfig
@@ -42,6 +43,7 @@ abstract public function dimensions(): iterable;
4243
public function canRetrieveOptions($config, string $configId = null): bool
4344
{
4445
$dimensions = $this->dimensions();
46+
$dimensions = $dimensions instanceof Iterator ? iterator_to_array($dimensions) : $dimensions;
4547

4648
if ($this instanceof RequiresConfigId) {
4749
$dimensions[] = $configId;
@@ -82,6 +84,7 @@ public function canRetrieveOptions($config, string $configId = null): bool
8284
public function options($config, string $configId = null)
8385
{
8486
$dimensions = $this->dimensions();
87+
$dimensions = $dimensions instanceof Iterator ? iterator_to_array($dimensions) : $dimensions;
8588

8689
if ($this instanceof RequiresConfigId) {
8790
$dimensions[] = $configId;
@@ -115,7 +118,12 @@ public function options($config, string $configId = null)
115118
}
116119

117120
if ($this instanceof ProvidesDefaultOptions) {
118-
$config = array_replace_recursive($this->defaultOptions(), $config);
121+
$options = $this->defaultOptions();
122+
123+
$config = array_replace_recursive(
124+
$options instanceof Iterator ? iterator_to_array($options) : (array)$options,
125+
(array)$config
126+
);
119127
}
120128
return $config;
121129
}

src/ProvidesDefaultOptions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ interface ProvidesDefaultOptions
2222
/**
2323
* Returns a list of default options, which are merged in \Interop\Config\RequiresConfig::options()
2424
*
25-
* @return mixed[] List with default options and values, can be nested
25+
* @return iterable List with default options and values, can be nested
2626
*/
27-
public function defaultOptions(): array;
27+
public function defaultOptions(): iterable;
2828
}

0 commit comments

Comments
 (0)