diff --git a/src/DI/Extensions/DecoratorExtension.php b/src/DI/Extensions/DecoratorExtension.php index 3db4e80c5..0651f9e69 100644 --- a/src/DI/Extensions/DecoratorExtension.php +++ b/src/DI/Extensions/DecoratorExtension.php @@ -63,7 +63,9 @@ public function addTags(string $type, array $tags): void private function findByType(string $type): array { return array_filter($this->getContainerBuilder()->getDefinitions(), function ($def) use ($type) { - return is_a($def->getType(), $type, true) || is_a($def->getImplement(), $type, true); + return $def->getImplementMode() === $def::IMPLEMENT_MODE_GET + ? is_a($def->getImplement(), $type, true) + : (is_a($def->getType(), $type, true) || is_a($def->getImplement(), $type, true)); }); } } diff --git a/tests/DI/DecoratorExtension.factories.accessor.phpt b/tests/DI/DecoratorExtension.factories.accessor.phpt new file mode 100644 index 000000000..17fbc928f --- /dev/null +++ b/tests/DI/DecoratorExtension.factories.accessor.phpt @@ -0,0 +1,49 @@ +addExtension('decorator', new Nette\DI\Extensions\DecoratorExtension); +$container = createContainer($compiler, ' +decorator: + Foo: + inject: yes + FooAccessor: + tags: [a] +services: + foo: Foo + acc: {implement: FooAccessor} +'); + + +$builder = $compiler->getContainerBuilder(); + +Assert::true($builder->getDefinition('foo')->getTag('inject')); +Assert::null($builder->getDefinition('foo')->getTag('a')); + +Assert::null($builder->getDefinition('acc')->getTag('inject')); +Assert::true($builder->getDefinition('acc')->getTag('a'));