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

nette / application / 9370306860

04 Jun 2024 03:54PM UTC coverage: 81.409% (-0.04%) from 81.445%
9370306860

push

github

dg
PresenterFactoryCallback: refreshes page instead of creating presenters dynamically

1 of 6 new or added lines in 2 files covered. (16.67%)

2 existing lines in 1 file now uncovered.

1883 of 2313 relevant lines covered (81.41%)

0.81 hits per line

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

13.33
/src/Bridges/ApplicationDI/PresenterFactoryCallback.php
1
<?php
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
declare(strict_types=1);
9

10
namespace Nette\Bridges\ApplicationDI;
11

12
use Nette;
13

14

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

27

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

38
                if (count($services) === 1) {
×
UNCOV
39
                        return $this->container->createService($services[0]);
×
40
                }
41

NEW
42
                if ($this->touchToRefresh && class_exists($class)) {
×
43
                        touch($this->touchToRefresh);
×
NEW
44
                        echo 'Class ' . htmlspecialchars($class) . ' was not found in DI container. If you just created this presenter, it should be enough to refresh the page. It will happen automatically in 5 seconds.';
×
NEW
45
                        header('Refresh: 5');
×
NEW
46
                        exit;
×
47
                }
48

NEW
49
                throw new Nette\Application\InvalidPresenterException("No services of type $class found.");
×
50
        }
51
}
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

© 2025 Coveralls, Inc