Completed
Push — 1.x ( f90c20...192b3e )
by Akihito
26s queued 14s
created

Injector::factory()   A

Complexity

Conditions 6
Paths 24

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 24
rs 9.2222
c 1
b 0
f 0
cc 6
nc 24
nop 3
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 Symfony\Component\Cache\Adapter\ApcuAdapter;
12
use Symfony\Component\Cache\Adapter\ChainAdapter;
13
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
14
use Symfony\Contracts\Cache\CacheInterface;
15
16
use function str_replace;
17
18
/**
19
 * @see PackageInjector
20
 */
21
final class Injector
22
{
23
    /**
24
     * @codeCoverageIgnore
25
     */
26
    private function __construct()
27
    {
28
    }
29
30
    public static function getInstance(string $appName, string $context, string $appDir, ?CacheInterface $cache = null): InjectorInterface
31
    {
32
        $meta = new Meta($appName, $context, $appDir);
33
        $cacheNamespace = str_replace('/', '_', $appDir) . $context;
34
        $cache ??= new ChainAdapter([new ApcuAdapter($cacheNamespace), new FilesystemAdapter('', 0, $meta->tmpDir . '/injector')]);
35
36
        return PackageInjector::getInstance($meta, $context, $cache);
37
    }
38
39
    public static function getOverrideInstance(string $appName, string $context, string $appDir, AbstractModule $overrideModule): InjectorInterface
40
    {
41
        return PackageInjector::factory(new Meta($appName, $context, $appDir), $context, $overrideModule);
42
    }
43
}
44