Skip to content

Commit

Permalink
ContainerFactory::$configFiles can contain arrays with configuration [C…
Browse files Browse the repository at this point in the history
…loses #26]
  • Loading branch information
dg committed Nov 8, 2014
1 parent 67075d6 commit 236f386
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/DI/ContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ContainerFactory extends Nette\Object
/** @var array */
public $config = array();

/** @var array [file, section] */
/** @var array [file|array, section] */
public $configFiles = array();

/** @var string */
Expand Down Expand Up @@ -71,7 +71,9 @@ protected function generateCode()

$code = "<?php\n";
foreach ($this->configFiles as $info) {
$code .= "// source: $info[0] $info[1]\n";
if (is_scalar($info[0])) {
$code .= "// source: $info[0] $info[1]\n";
}
}
$code .= "\n" . $compiler->compile($config, $this->class, $this->parentClass);

Expand All @@ -90,7 +92,8 @@ protected function generateConfig()
$config = array();
$loader = $this->createLoader();
foreach ($this->configFiles as $info) {
$config = Config\Helpers::merge($loader->load($info[0], $info[1]), $config);
$info = is_scalar($info[0]) ? $loader->load($info[0], $info[1]) : $info[0];
$config = Config\Helpers::merge($info, $config);
}
$this->dependencies = array_merge($this->dependencies, $loader->getDependencies());

Expand Down
9 changes: 9 additions & 0 deletions tests/DI/ContainerFactory.basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,12 @@ $factory->class = 'My';
$container = $factory->create();
Assert::type($factory->class, $container);
Assert::type($factory->parentClass, $container);

$factory->class = 'My2';
$factory->config = array('parameters' => array('foo' => 'a'));
$factory->configFiles = array(
array(Tester\FileMock::create('parameters: {foo: b}', 'neon'), NULL),
array(array('parameters' => array('foo' => 'c')), NULL),
);
$container = $factory->create();
Assert::same(array('foo' => 'c'), $container->parameters);

0 comments on commit 236f386

Please sign in to comment.