Skip to content

Commit

Permalink
DecoratorExtension: do not decorate accessors by inner type (possible…
Browse files Browse the repository at this point in the history
… BC break)
  • Loading branch information
dg committed Mar 28, 2018
1 parent 95b5869 commit a300c8b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/DI/Extensions/DecoratorExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
}
}
47 changes: 47 additions & 0 deletions tests/DI/DecoratorExtension.factories.accessor.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/**
* Test: Nette\DI\Compiler: service decorators && generated factories
*/

use Nette\DI;
use Tester\Assert;


require __DIR__ . '/../bootstrap.php';

interface FooAccessor
{

/**
* @return Foo
*/
public function get();
}

class Foo
{
}


$compiler = new DI\Compiler;
$compiler->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'));

0 comments on commit a300c8b

Please sign in to comment.