From a300c8b8e8549595ab90c04d8ee21b8b2a5a88f9 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 28 Mar 2018 19:42:23 +0200 Subject: [PATCH] DecoratorExtension: do not decorate accessors by inner type (possible BC break) --- src/DI/Extensions/DecoratorExtension.php | 3 +- ...DecoratorExtension.factories.accessor.phpt | 47 +++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 tests/DI/DecoratorExtension.factories.accessor.phpt diff --git a/src/DI/Extensions/DecoratorExtension.php b/src/DI/Extensions/DecoratorExtension.php index 2de747c04..35ad35ff1 100644 --- a/src/DI/Extensions/DecoratorExtension.php +++ b/src/DI/Extensions/DecoratorExtension.php @@ -61,7 +61,8 @@ public function addTags($type, array $tags) private function findByType($type) { return array_filter($this->getContainerBuilder()->getDefinitions(), function ($def) use ($type) { - return is_a($def->getType(), $type, true) || is_a($def->getImplement(), $type, true); + return is_a($def->getImplement(), $type, true) + || ($def->getImplementMode() !== $def::IMPLEMENT_MODE_GET && is_a($def->getType(), $type, true)); }); } } diff --git a/tests/DI/DecoratorExtension.factories.accessor.phpt b/tests/DI/DecoratorExtension.factories.accessor.phpt new file mode 100644 index 000000000..622f6e3bb --- /dev/null +++ b/tests/DI/DecoratorExtension.factories.accessor.phpt @@ -0,0 +1,47 @@ +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'));