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

nepada / presenter-mapping / 6342715702

28 Sep 2023 06:12PM UTC coverage: 91.667%. Remained the same
6342715702

push

github

xificurk
Drop useless dev dependency

77 of 84 relevant lines covered (91.67%)

0.92 hits per line

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

90.0
/src/Bridges/PresenterMappingDI/PresenterMappingExtension.php
1
<?php
2
declare(strict_types = 1);
3

4
namespace Nepada\Bridges\PresenterMappingDI;
5

6
use Nepada\PresenterMapping;
7
use Nette;
8

9
class PresenterMappingExtension extends Nette\DI\CompilerExtension
10
{
11

12
    public function getConfigSchema(): Nette\Schema\Schema
13
    {
14
        return Nette\Schema\Expect::structure([]);
1✔
15
    }
16

17
    public function loadConfiguration(): void
18
    {
19
        $container = $this->getContainerBuilder();
1✔
20

21
        $container->addDefinition($this->prefix('presenterMapper'))
1✔
22
            ->setType(PresenterMapping\PresenterMapper::class);
1✔
23

24
        $presenterFactory = $this->getNettePresenterFactory();
1✔
25
        $factory = $presenterFactory->getFactory();
1✔
26
        $arguments = $factory->getEntity() !== null ? $factory->arguments : [];
1✔
27
        array_unshift($arguments, $this->prefix('@presenterMapper'));
1✔
28
        $presenterFactory->setFactory(PresenterMapping\PresenterFactory::class, $arguments);
1✔
29
    }
1✔
30

31
    /**
32
     * Make sure that ApplicationExtension is loaded before us and return its PresenterFactory definition.
33
     */
34
    private function getNettePresenterFactory(): Nette\DI\Definitions\ServiceDefinition
35
    {
36
        /** @var Nette\Bridges\ApplicationDI\ApplicationExtension[] $applicationExtension */
37
        $applicationExtension = $this->compiler->getExtensions(Nette\Bridges\ApplicationDI\ApplicationExtension::class);
1✔
38
        if ($applicationExtension === []) {
1✔
39
            throw new \LogicException('ApplicationExtension not found, did you register it in your configuration?');
×
40
        }
41

42
        $container = $this->getContainerBuilder();
1✔
43
        $presenterFactory = reset($applicationExtension)->prefix('presenterFactory');
1✔
44
        if (! $container->hasDefinition($presenterFactory)) {
1✔
45
            throw new \LogicException('PresenterFactory service from ApplicationExtension not found. Make sure ApplicationExtension is loaded before PresenterMappingExtension.');
×
46
        }
47

48
        $serviceDefinition = $container->getDefinition($presenterFactory);
1✔
49
        assert($serviceDefinition instanceof Nette\DI\Definitions\ServiceDefinition);
1✔
50

51
        return $serviceDefinition;
1✔
52
    }
53

54
}
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