From 4f3b250709226c70c8ca0a35f796877bcb72b10d Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 26 Mar 2019 19:37:01 +0100 Subject: [PATCH] PresenterFactoryCallback: throws error "Refresh browser" when DI is unable to create presenter instance It may be caused by 'di > export > types' setting. --- .../ApplicationDI/PresenterFactoryCallback.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Bridges/ApplicationDI/PresenterFactoryCallback.php b/src/Bridges/ApplicationDI/PresenterFactoryCallback.php index dd7df6999..c02fa4574 100644 --- a/src/Bridges/ApplicationDI/PresenterFactoryCallback.php +++ b/src/Bridges/ApplicationDI/PresenterFactoryCallback.php @@ -47,8 +47,16 @@ public function __invoke(string $class): Nette\Application\IPresenter touch($this->touchToRefresh); } - $presenter = $this->container->createInstance($class); - $this->container->callInjects($presenter); + try { + $presenter = $this->container->createInstance($class); + $this->container->callInjects($presenter); + } catch (Nette\DI\MissingServiceException | Nette\DI\ServiceCreationException $e) { + if ($this->touchToRefresh && class_exists($class)) { + throw new \Exception("Refresh your browser. New presenter $class was found.", 0, $e); + } + throw $e; + } + if ($presenter instanceof Nette\Application\UI\Presenter && $presenter->invalidLinkMode === null) { $presenter->invalidLinkMode = $this->invalidLinkMode; }