From d9bd6d7828ff1b8331a50f180bc2a3099e51ef88 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 4 Feb 2019 19:49:12 +0100 Subject: [PATCH] ApplicationExtension: tag nette.presenter replaced by findByType() --- .../ApplicationDI/ApplicationExtension.php | 3 +-- .../PresenterFactoryCallback.php | 2 +- .../Bridges.DI/ApplicationExtension.scan.phpt | 24 ++++++++----------- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/Bridges/ApplicationDI/ApplicationExtension.php b/src/Bridges/ApplicationDI/ApplicationExtension.php index b8a26ec5d..99ee5651b 100644 --- a/src/Bridges/ApplicationDI/ApplicationExtension.php +++ b/src/Bridges/ApplicationDI/ApplicationExtension.php @@ -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]); diff --git a/src/Bridges/ApplicationDI/PresenterFactoryCallback.php b/src/Bridges/ApplicationDI/PresenterFactoryCallback.php index 3834fa82d..dd7df6999 100644 --- a/src/Bridges/ApplicationDI/PresenterFactoryCallback.php +++ b/src/Bridges/ApplicationDI/PresenterFactoryCallback.php @@ -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) . '.'); diff --git a/tests/Bridges.DI/ApplicationExtension.scan.phpt b/tests/Bridges.DI/ApplicationExtension.scan.phpt index da7bbed49..e68ac7350 100644 --- a/tests/Bridges.DI/ApplicationExtension.scan.phpt +++ b/tests/Bridges.DI/ApplicationExtension.scan.phpt @@ -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()); });