Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/hotfix/inconsistency-default-opt…
Browse files Browse the repository at this point in the history
…ions'
  • Loading branch information
sandrokeil committed Dec 9, 2016
2 parents f60e477 + 5511eb4 commit 74fc934
Show file tree
Hide file tree
Showing 13 changed files with 327 additions and 52 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,27 @@

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

## 2.0.1 (2016-12-09)
This release contains **no** BC break.

### Added

* More test cases for iterable return type and `\Iterator` objects

### Deprecated

* Nothing

### Removed

* Nothing

### Fixed

* [#34](https://github.com/sandrokeil/interop-config/issue/34): Inconsistent return type in `defaultOptions()`
* `defaultOptions()` method return type is `iterable` but `array` is still valid


## 2.0.0 (2016-12-06)
To upgrade from version 1.x to version 2.x you have to add the PHP scalar types of the interfaces to your implemented
factory methods.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -38,7 +38,7 @@ You should have coding conventions and you should have config conventions. If no

## Installation

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

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.
Expand Down
2 changes: 1 addition & 1 deletion doc/book/intro.md
Expand Up @@ -36,7 +36,7 @@ You should have coding conventions and you should have config conventions. If no
`interop-config` is universally applicable! See further documentation for more details.

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

Run `composer require sandrokeil/interop-config` to install interop-config.
Expand Down
8 changes: 4 additions & 4 deletions doc/book/quick-start.md
Expand Up @@ -39,14 +39,14 @@ class MyAwesomeFactory implements RequiresConfigId
public function dimensions() : iterable
{
return ['vendor-package'];
}
public function canRetrieveOptions($config, $configId = null) : bool
}

public function canRetrieveOptions($config, string $configId = null) : bool
{
// custom implementation depending on specifications
}

public function options($config, $configId = null)
public function options($config, string $configId = null)
{
// custom implementation depending on specifications
}
Expand Down
4 changes: 2 additions & 2 deletions doc/bookdown.json
@@ -1,5 +1,5 @@
{
"title": "interop-config",
"title": "interop-config - configurable factories",
"content": [
{"getting-started": "book/getting-started/bookdown.json"},
{"reference": "book/reference/bookdown.json"},
Expand All @@ -8,5 +8,5 @@
"target": "./html",
"tocDepth": 2,
"template": "../vendor/tobiju/bookdown-bootswatch-templates/templates/main.php",
"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>"
"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>"
}
10 changes: 9 additions & 1 deletion src/ConfigurationTrait.php
Expand Up @@ -13,6 +13,7 @@

use ArrayAccess;
use Interop\Config\Exception;
use Iterator;

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

if ($this instanceof RequiresConfigId) {
$dimensions[] = $configId;
Expand Down Expand Up @@ -82,6 +84,7 @@ public function canRetrieveOptions($config, string $configId = null): bool
public function options($config, string $configId = null)
{
$dimensions = $this->dimensions();
$dimensions = $dimensions instanceof Iterator ? iterator_to_array($dimensions) : $dimensions;

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

if ($this instanceof ProvidesDefaultOptions) {
$config = array_replace_recursive($this->defaultOptions(), $config);
$options = $this->defaultOptions();

$config = array_replace_recursive(
$options instanceof Iterator ? iterator_to_array($options) : (array)$options,
(array)$config
);
}
return $config;
}
Expand Down
4 changes: 2 additions & 2 deletions src/ProvidesDefaultOptions.php
Expand Up @@ -22,7 +22,7 @@ interface ProvidesDefaultOptions
/**
* Returns a list of default options, which are merged in \Interop\Config\RequiresConfig::options()
*
* @return mixed[] List with default options and values, can be nested
* @return iterable List with default options and values, can be nested
*/
public function defaultOptions(): array;
public function defaultOptions(): iterable;
}

0 comments on commit 74fc934

Please sign in to comment.