• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nette / application / 27919019709

21 Jun 2026 10:08PM UTC coverage: 84.111% (+0.05%) from 84.059%
27919019709

push

github

dg
phpstan fix

2038 of 2423 relevant lines covered (84.11%)

0.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

9.52
/src/Bridges/ApplicationDI/PresenterFactoryCallback.php
1
<?php declare(strict_types=1);
2

3
/**
4
 * This file is part of the Nette Framework (https://nette.org)
5
 * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6
 */
7

8
namespace Nette\Bridges\ApplicationDI;
9

10
use Nette;
11
use function array_filter, array_values, class_exists, count, implode, touch;
12

13

14
/**
15
 * PresenterFactory callback.
16
 * @internal
17
 */
18
final class PresenterFactoryCallback
19
{
20
        public function __construct(
1✔
21
                private readonly Nette\DI\Container $container,
22
                private readonly int $invalidLinkMode,
23
                private readonly ?string $touchToRefresh,
24
        ) {
25
        }
1✔
26

27

28
        /** @param class-string<Nette\Application\IPresenter>  $class */
29
        public function __invoke(string $class): Nette\Application\IPresenter
30
        {
31
                $services = $this->container->findByType($class);
×
32
                if (count($services) > 1) {
×
33
                        $services = array_values(array_filter($services, fn($service) => $this->container->getServiceType($service) === $class));
×
34
                        if (count($services) > 1) {
×
35
                                throw new Nette\Application\InvalidPresenterException("Multiple services of type $class found: " . implode(', ', $services) . '.');
×
36
                        }
37
                }
38

39
                if (count($services) === 1) {
×
40
                        $presenter = $this->container->createService($services[0]);
×
41
                        assert($presenter instanceof Nette\Application\IPresenter);
42
                        return $presenter;
×
43
                }
44

45
                if ($this->touchToRefresh) {
×
46
                        touch($this->touchToRefresh);
×
47
                }
48

49
                try {
50
                        $presenter = $this->container->createInstance($class);
×
51
                        $this->container->callInjects($presenter);
×
52
                } catch (Nette\DI\MissingServiceException | Nette\DI\ServiceCreationException $e) {
×
53
                        if ($this->touchToRefresh && class_exists($class)) {
×
54
                                throw new \Exception("Refresh your browser. New presenter $class was found.", 0, $e);
×
55
                        }
56

57
                        throw $e;
×
58
                }
59

60
                if ($presenter instanceof Nette\Application\UI\Presenter && !$presenter->invalidLinkMode) {
×
61
                        $presenter->invalidLinkMode = $this->invalidLinkMode;
×
62
                }
63

64
                return $presenter;
×
65
        }
66
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc