Skip to content

Commit

Permalink
Merge 687c5e8 into ef261dc
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangut committed Sep 17, 2018
2 parents ef261dc + 687c5e8 commit 01fde1d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
22 changes: 12 additions & 10 deletions src/ContainerBuilder.php
Expand Up @@ -306,24 +306,26 @@ public function wrapContainer(ContainerInterface $otherContainer) : self
/**
* Add definitions to the container.
*
* @param string|array|DefinitionSource $definitions Can be an array of definitions, the
* @param string[]|array[]|DefinitionSource[] $definitions Can be an array of definitions, the
* name of a file containing definitions
* or a DefinitionSource object.
* @return $this
*/
public function addDefinitions($definitions) : self
public function addDefinitions(...$definitions) : self
{
$this->ensureNotLocked();

if (!is_string($definitions) && !is_array($definitions) && !($definitions instanceof DefinitionSource)) {
throw new InvalidArgumentException(sprintf(
'%s parameter must be a string, an array or a DefinitionSource object, %s given',
'ContainerBuilder::addDefinitions()',
is_object($definitions) ? get_class($definitions) : gettype($definitions)
));
}
foreach ($definitions as $definition) {
if (!is_string($definition) && !is_array($definition) && !($definition instanceof DefinitionSource)) {
throw new InvalidArgumentException(sprintf(
'%s parameter must be a string, an array or a DefinitionSource object, %s given',
'ContainerBuilder::addDefinitions()',
is_object($definition) ? get_class($definition) : gettype($definition)
));
}

$this->definitionSources[] = $definitions;
$this->definitionSources[] = $definition;
}

return $this;
}
Expand Down
9 changes: 3 additions & 6 deletions tests/UnitTest/ContainerBuilderTest.php
Expand Up @@ -94,8 +94,7 @@ public function should_allow_to_add_custom_definition_sources()
$builder = new ContainerBuilder(FakeContainer::class);

// Custom definition sources should be chained correctly
$builder->addDefinitions(new DefinitionArray(['foo' => 'bar']));
$builder->addDefinitions(new DefinitionArray(['foofoo' => 'barbar']));
$builder->addDefinitions(new DefinitionArray(['foo' => 'bar']), new DefinitionArray(['foofoo' => 'barbar']));

/** @var FakeContainer $container */
$container = $builder->build();
Expand All @@ -117,8 +116,7 @@ public function should_chain_definition_sources_in_reverse_order()
{
$builder = new ContainerBuilder(FakeContainer::class);

$builder->addDefinitions(new DefinitionArray(['foo' => 'bar']));
$builder->addDefinitions(new DefinitionArray(['foo' => 'bim']));
$builder->addDefinitions(new DefinitionArray(['foo' => 'bar']), new DefinitionArray(['foo' => 'bim']));

/** @var FakeContainer $container */
$container = $builder->build();
Expand All @@ -136,8 +134,7 @@ public function should_allow_to_add_definitions_in_an_array()
$builder = new ContainerBuilder(FakeContainer::class);

// Custom definition sources should be chained correctly
$builder->addDefinitions(['foo' => 'bar']);
$builder->addDefinitions(['foofoo' => 'barbar']);
$builder->addDefinitions(['foo' => 'bar'], ['foofoo' => 'barbar']);

/** @var FakeContainer $container */
$container = $builder->build();
Expand Down

0 comments on commit 01fde1d

Please sign in to comment.