Skip to content

Commit

Permalink
PresenterFactoryCallback: refreshes page instead of creating presente…
Browse files Browse the repository at this point in the history
…rs dynamically
  • Loading branch information
dg committed May 13, 2024
1 parent 1e86896 commit 4972a39
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/Bridges/ApplicationDI/ApplicationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function loadConfiguration(): void
->setType(Nette\Application\IPresenterFactory::class)
->setFactory(Nette\Application\PresenterFactory::class, [new Definitions\Statement(
Nette\Bridges\ApplicationDI\PresenterFactoryCallback::class,
[1 => $this->invalidLinkMode, $touch ?? null],
[1 => $touch ?? null],
)]);

if ($config->mapping) {
Expand Down
22 changes: 4 additions & 18 deletions src/Bridges/ApplicationDI/PresenterFactoryCallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ final class PresenterFactoryCallback
{
public function __construct(
private readonly Nette\DI\Container $container,
private readonly int $invalidLinkMode,
private readonly ?string $touchToRefresh,
) {
}
Expand All @@ -40,25 +39,12 @@ public function __invoke(string $class): Nette\Application\IPresenter
return $this->container->createService($services[0]);
}

if ($this->touchToRefresh) {
if ($this->touchToRefresh && class_exists($class)) {
touch($this->touchToRefresh);
header('Refresh: 0');
exit;
}

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 && !isset($presenter->invalidLinkMode)) {
$presenter->invalidLinkMode = $this->invalidLinkMode;
}

return $presenter;
throw new Nette\Application\InvalidPresenterException("No services of type $class found.");
}
}

0 comments on commit 4972a39

Please sign in to comment.