Skip to content

Commit 82c49e0

Browse files
committed
PresenterFactoryCallback: refreshes page instead of creating presenters dynamically (BC break)
TODO: scanDir must be active
1 parent d46dbb0 commit 82c49e0

File tree

2 files changed

+6
-19
lines changed

2 files changed

+6
-19
lines changed

src/Bridges/ApplicationDI/ApplicationExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function loadConfiguration(): void
9797
->setType(Nette\Application\IPresenterFactory::class)
9898
->setFactory(Nette\Application\PresenterFactory::class, [new Definitions\Statement(
9999
Nette\Bridges\ApplicationDI\PresenterFactoryCallback::class,
100-
[1 => $this->invalidLinkMode, $touch ?? null],
100+
[1 => $touch ?? null],
101101
)]);
102102

103103
if ($config->mapping) {

src/Bridges/ApplicationDI/PresenterFactoryCallback.php

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ final class PresenterFactoryCallback
2121
{
2222
public function __construct(
2323
private readonly Nette\DI\Container $container,
24-
private readonly int $invalidLinkMode,
2524
private readonly ?string $touchToRefresh,
2625
) {
2726
}
@@ -41,25 +40,13 @@ public function __invoke(string $class): Nette\Application\IPresenter
4140
return $this->container->createService($services[0]);
4241
}
4342

44-
if ($this->touchToRefresh) {
43+
if ($this->touchToRefresh && class_exists($class)) {
4544
touch($this->touchToRefresh);
45+
echo 'Class ' . htmlspecialchars($class) . ' was not found in DI container.<br><br>If you just created this presenter, it should be enough to refresh the page. It will happen automatically in 5 seconds.<br><br>Otherwise, please check the configuration of your DI container.';
46+
header('Refresh: 5');
47+
exit;
4648
}
4749

48-
try {
49-
$presenter = $this->container->createInstance($class);
50-
$this->container->callInjects($presenter);
51-
} catch (Nette\DI\MissingServiceException | Nette\DI\ServiceCreationException $e) {
52-
if ($this->touchToRefresh && class_exists($class)) {
53-
throw new \Exception("Refresh your browser. New presenter $class was found.", 0, $e);
54-
}
55-
56-
throw $e;
57-
}
58-
59-
if ($presenter instanceof Nette\Application\UI\Presenter && !isset($presenter->invalidLinkMode)) {
60-
$presenter->invalidLinkMode = $this->invalidLinkMode;
61-
}
62-
63-
return $presenter;
50+
throw new Nette\Application\InvalidPresenterException("No services of type $class found.");
6451
}
6552
}

0 commit comments

Comments
 (0)