ImportAppModule::configure()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 7
c 2
b 0
f 0
dl 0
loc 9
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Package\Module;
6
7
use BEAR\AppMeta\Meta;
8
use BEAR\Package\Module\Import\ImportApp;
9
use BEAR\Resource\Annotation\ImportAppConfig;
10
use BEAR\Resource\Module\SchemeCollectionProvider;
11
use BEAR\Resource\SchemeCollectionInterface;
12
use Override;
13
use Ray\Di\AbstractModule;
14
use Ray\Di\Exception\NotFound;
15
16
/**
17
 * Provides SchemeCollectionInterface and derived bindings
18
 *
19
 * The following bindings are provided:
20
 *
21
 * SchemeCollectionInterface
22
 * SchemeCollectionInterface:original
23
 * :ImportAppConfig
24
 */
25
final class ImportAppModule extends AbstractModule
26
{
27
    /**
28
     * Import scheme config
29
     *
30
     * @var array<ImportApp>
31
     */
32
    private array $importApps = [];
33
34
    /** @param array<ImportApp> $importApps */
35
    public function __construct(array $importApps)
36
    {
37
        foreach ($importApps as $importApp) {
38
            // create import config
39
            $this->importApps[] = $importApp;
40
        }
41
42
        parent::__construct();
43
    }
44
45
    /**
46
     * {@inheritDoc}
47
     *
48
     * @throws NotFound
49
     */
50
    #[Override]
51
    protected function configure(): void
52
    {
53
        $this->bind()->annotatedWith(ImportAppConfig::class)->toInstance($this->importApps);
54
        $this->bind(SchemeCollectionInterface::class)->annotatedWith('original')->toProvider(SchemeCollectionProvider::class);
55
        $this->bind(SchemeCollectionInterface::class)->toProvider(ImportSchemeCollectionProvider::class);
56
        foreach ($this->importApps as $app) {
57
            $meta = new Meta($app->appName, $app->context, $app->appDir);
58
            $this->install(new ResourceObjectModule($meta->getResourceListGenerator()));
59
        }
60
    }
61
}
62