Completed
Pull Request — 1.x (#10)
by
unknown
01:51
created

Boot::getContxtualModule()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
nc 5
nop 2
dl 0
loc 17
ccs 11
cts 11
cp 1
crap 4
rs 9.7
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the BEAR.Middleware package.
4
 *
5
 * @license http://opensource.org/licenses/MIT MIT
6
 */
7
namespace BEAR\Middleware;
8
9
use BEAR\AppMeta\AbstractAppMeta;
10
use BEAR\Middleware\Module\MiddlewareModule;
11
use BEAR\Middleware\Module\StreamModule;
12
use BEAR\Package\Module;
13
use Ray\Compiler\DiCompiler;
14
use Ray\Compiler\Exception\NotCompiled;
15
use Ray\Compiler\ScriptInjector;
16
use Ray\Di\InjectorInterface;
17
18
class Boot
19
{
20 3
    public function getInjector(AbstractAppMeta $appMeta, $contexts)
21
    {
22
        try {
23 3
            $injector = (new ScriptInjector($appMeta->tmpDir))->getInstance(InjectorInterface::class);
24 3
        } catch (NotCompiled $e) {
25 3
            $module = (new Module)($appMeta, $contexts);
26 2
            $module->override(new MiddlewareModule());
27 2
            $compiler = new DiCompiler(new StreamModule($module), $appMeta->tmpDir);
28 2
            $compiler->compile();
29 2
            $injector = (new ScriptInjector($appMeta->tmpDir))->getInstance(InjectorInterface::class);
30
        }
31
32 2
        return $injector;
33
    }
34
}
35