Skip to content

Commit

Permalink
ensure array or traversable
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangut committed Mar 26, 2017
1 parent fd0a6ff commit d0d90a0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ In order for you to use definitions cache you have to `require doctrine/cache`.
#### Additional settings

* `containerClass`, container class that will be built, must implement `\Interop\Container\ContainerInterface`, `\Di\FactoryInterface` and `\DI\InvokerInterface` (`\Jgut\Slim\PHPDI\Container` by default)
* `definitions`, an array of paths to definition files/directories or arrays of definitions. _Definitions are loaded in order of appearance_
* `definitions`, an array or traversable of paths to definition files/directories or arrays of definitions. _Definitions are loaded in order of appearance_

## Services registration order

Expand Down
File renamed without changes.
14 changes: 8 additions & 6 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,13 @@ public function __construct($configurations = [])
throw new \InvalidArgumentException('Configurations must be a traversable');
}

if (count($configurations)) {
$this->seedConfigurations($configurations);
}
$this->seedConfigurations($configurations);
}

/**
* Seed configurations.
*
* @param $configurations
* @param array|\Traversable $configurations
*/
protected function seedConfigurations($configurations)
{
Expand Down Expand Up @@ -243,7 +241,7 @@ public function getDefinitions()
/**
* Set definitions.
*
* @param string|array $definitions
* @param string|array|\Traversable $definitions
*
* @throws \InvalidArgumentException
*
Expand All @@ -255,9 +253,13 @@ public function setDefinitions($definitions)
$definitions = [$definitions];
}

if ($definitions instanceof \Traversable) {
$definitions = iterator_to_array($definitions);
}

if (!is_array($definitions)) {
throw new \InvalidArgumentException(
sprintf('Definitions must be a string or an array. %s given', gettype($definitions))
sprintf('Definitions must be a string or traversable. %s given', gettype($definitions))
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/PHPDI/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function testInvalidContainerClass()

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Definitions must be a string or an array. integer given
* @expectedExceptionMessage Definitions must be a string or traversable. integer given
*/
public function testInvalidDefinitionsType()
{
Expand Down

0 comments on commit d0d90a0

Please sign in to comment.