Injector::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 0
c 1
b 0
f 0
dl 0
loc 2
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Package;
6
7
use BEAR\AppMeta\Meta;
8
use BEAR\Package\Injector\PackageInjector;
9
use Ray\Di\AbstractModule;
10
use Ray\Di\InjectorInterface;
11
use Ray\PsrCacheModule\LocalCacheProvider;
12
use Symfony\Contracts\Cache\CacheInterface;
13
14
use function str_replace;
15
16
/** @see PackageInjector */
17
final class Injector
18
{
19
    /** @codeCoverageIgnore */
20
    private function __construct()
21
    {
22
    }
23
24
    public static function getInstance(string $appName, string $context, string $appDir, CacheInterface|null $cache = null): InjectorInterface
25
    {
26
        $meta = new Meta($appName, $context, $appDir);
27
        $cacheNamespace = str_replace('\\', '_', $appName) . $context;
28
        $cache ??= (new LocalCacheProvider($meta->tmpDir . '/injector', $cacheNamespace))->get();
29
30
        return PackageInjector::getInstance($meta, $context, $cache);
31
    }
32
33
    public static function getOverrideInstance(string $appName, string $context, string $appDir, AbstractModule $overrideModule): InjectorInterface
34
    {
35
        return PackageInjector::factory(new Meta($appName, $context, $appDir), $context, $overrideModule);
36
    }
37
}
38