Skip to content

Commit 629f157

Browse files
committed
Compiler: InjectExtension is moved after extensions added by ExtensionsExtension [Closes #88]
1 parent db617ef commit 629f157

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/DI/Compiler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,6 @@ public function processParameters()
155155
/** @internal */
156156
public function processExtensions()
157157
{
158-
$last = $this->getExtensions(Extensions\InjectExtension::class);
159-
$this->extensions = array_merge(array_diff_key($this->extensions, $last), $last);
160-
161158
$this->config = Helpers::expand(array_diff_key($this->config, self::$reserved), $this->builder->parameters)
162159
+ array_intersect_key($this->config, self::$reserved);
163160

@@ -166,6 +163,9 @@ public function processExtensions()
166163
$extension->loadConfiguration();
167164
}
168165

166+
$last = $this->getExtensions(Extensions\InjectExtension::class);
167+
$this->extensions = array_merge(array_diff_key($this->extensions, $last), $last);
168+
169169
$extensions = array_diff_key($this->extensions, $first);
170170
foreach (array_intersect_key($extensions, $this->config) as $name => $extension) {
171171
$extension->setConfig($this->config[$name] ?: []);

tests/DI/InjectExtension.basic.phpt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class LastExtension extends DI\CompilerExtension
4545
function beforeCompile()
4646
{
4747
// note that services should be added in loadConfiguration()
48-
$this->getContainerBuilder()->addDefinition('one')
48+
$this->getContainerBuilder()->addDefinition($this->prefix('one'))
4949
->setClass('Service')
5050
->setInject(TRUE);
5151
}
@@ -54,8 +54,12 @@ class LastExtension extends DI\CompilerExtension
5454

5555
$compiler = new DI\Compiler;
5656
$compiler->addExtension('inject', new Nette\DI\Extensions\InjectExtension);
57+
$compiler->addExtension('extensions', new Nette\DI\Extensions\ExtensionsExtension);
5758
$compiler->addExtension('last', new LastExtension);
5859
$container = createContainer($compiler, '
60+
extensions:
61+
ext: LastExtension
62+
5963
services:
6064
- stdClass
6165
two:
@@ -75,7 +79,16 @@ Assert::equal([
7579
new Statement(['@self', 'injectC']),
7680
new Statement(['@self', '$c'], ['@\\stdClass']),
7781
new Statement(['@self', '$a'], ['@\\stdClass']),
78-
], $builder->getDefinition('one')->getSetup());
82+
], $builder->getDefinition('last.one')->getSetup());
83+
84+
Assert::equal([
85+
new Statement(['@self', 'injectB']),
86+
new Statement(['@self', 'injectA']),
87+
new Statement(['@self', 'injectD']),
88+
new Statement(['@self', 'injectC']),
89+
new Statement(['@self', '$c'], ['@\\stdClass']),
90+
new Statement(['@self', '$a'], ['@\\stdClass']),
91+
], $builder->getDefinition('ext.one')->getSetup());
7992

8093
Assert::equal([
8194
new Statement(['@self', 'injectB'], [1]),

0 commit comments

Comments
 (0)