Skip to content

Commit c4f97cb

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

File tree

2 files changed

+6
-19
lines changed

2 files changed

+6
-19
lines changed

src/Bridges/ApplicationDI/ApplicationExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function loadConfiguration(): void
9696
->setType(Nette\Application\IPresenterFactory::class)
9797
->setFactory(Nette\Application\PresenterFactory::class, [new Definitions\Statement(
9898
Nette\Bridges\ApplicationDI\PresenterFactoryCallback::class,
99-
[1 => $this->invalidLinkMode, $touch ?? null],
99+
[1 => $touch ?? null],
100100
)]);
101101

102102
if ($config->mapping) {

src/Bridges/ApplicationDI/PresenterFactoryCallback.php

+5-18
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ final class PresenterFactoryCallback
2020
{
2121
public function __construct(
2222
private readonly Nette\DI\Container $container,
23-
private readonly int $invalidLinkMode,
2423
private readonly ?string $touchToRefresh,
2524
) {
2625
}
@@ -40,25 +39,13 @@ public function __invoke(string $class): Nette\Application\IPresenter
4039
return $this->container->createService($services[0]);
4140
}
4241

43-
if ($this->touchToRefresh) {
42+
if ($this->touchToRefresh && class_exists($class)) {
4443
touch($this->touchToRefresh);
44+
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.';
45+
header('Refresh: 5');
46+
exit;
4547
}
4648

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

0 commit comments

Comments
 (0)