Permalink
Browse files

ApplicationExtension: tag nette.presenter replaced by findByType()

  • Loading branch information...
dg committed Feb 4, 2019
1 parent 8a654f3 commit 49729334885b7a4185439f047231165187cffab0
@@ -115,8 +115,7 @@ public function beforeCompile()
}
foreach ($all as $def) {
$def->addTag(Nette\DI\Extensions\InjectExtension::TAG_INJECT)
->addTag('nette.presenter', $def->getType());
$def->addTag(Nette\DI\Extensions\InjectExtension::TAG_INJECT);
if (is_subclass_of($def->getType(), UI\Presenter::class)) {
$def->addSetup('$invalidLinkMode', [$this->invalidLinkMode]);
@@ -38,7 +38,7 @@ public function __construct(Nette\DI\Container $container, int $invalidLinkMode,
public function __invoke(string $class): Nette\Application\IPresenter
{
$services = array_keys($this->container->findByTag('nette.presenter'), $class, true);
$services = $this->container->findByType($class);
if (count($services) > 1) {
throw new Nette\Application\InvalidPresenterException("Multiple services of type $class found: " . implode(', ', $services) . '.');
@@ -23,10 +23,9 @@ test(function () {
eval($code);
$container = new Container1;
$tags = $container->findByTag('nette.presenter');
Assert::count(1, array_keys($tags, NetteModule\ErrorPresenter::class, true));
Assert::count(1, array_keys($tags, NetteModule\MicroPresenter::class, true));
Assert::count(0, array_keys($tags, Nette\Application\UI\Presenter::class, true));
Assert::count(1, $container->findByType(NetteModule\ErrorPresenter::class));
Assert::count(1, $container->findByType(NetteModule\MicroPresenter::class));
Assert::count(0, $container->findByType(Nette\Application\UI\Presenter::class));
});
@@ -46,10 +45,9 @@ test(function () {
eval($code);
$container = new Container2;
$tags = $container->findByTag('nette.presenter');
Assert::count(1, array_keys($tags, 'BasePresenter', true));
Assert::count(1, array_keys($tags, 'Presenter1', true));
Assert::count(1, array_keys($tags, 'Presenter2', true));
Assert::count(3, $container->findByType(BasePresenter::class));
Assert::count(1, $container->findByType(Presenter1::class));
Assert::count(1, $container->findByType(Presenter2::class));
});
@@ -73,11 +71,9 @@ test(function () {
eval($code);
$container = new Container3;
$tags = $container->findByTag('nette.presenter');
Assert::count(1, array_keys($tags, 'BasePresenter', true));
Assert::count(1, array_keys($tags, 'Presenter1', true));
Assert::count(1, array_keys($tags, 'Presenter2', true));
Assert::count(3, $container->findByType(BasePresenter::class));
Assert::count(1, $container->findByType(Presenter1::class));
Assert::count(1, $container->findByType(Presenter2::class));
$tmp = array_keys($tags, 'Presenter1', true);
Assert::same('test', $container->getService((string) $tmp[0])->getView());
Assert::same('test', $container->getByType(Presenter1::class)->getView());
});

0 comments on commit 4972933

Please sign in to comment.