Completed
Push — 1.x ( d287ef...c40777 )
by Akihito
05:18 queued 17s
created

Compiler::__invoke()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 22
rs 9.2
cc 3
eloc 13
nc 3
nop 3
1
<?php
2
/**
3
 * This file is part of the BEAR.Package package.
4
 *
5
 * @license http://opensource.org/licenses/MIT MIT
6
 */
7
namespace BEAR\Package;
8
9
use BEAR\AppMeta\AppMeta;
10
use Doctrine\Common\Annotations\AnnotationReader;
11
use Doctrine\Common\Cache\Cache;
12
13
final class Compiler
14
{
15
    /**
16
     * @param string $appName application name "MyVendor|MyProject"
17
     * @param string $context application context "prod-app"
18
     * @param string $appDir  application path
19
     */
20
    public function __invoke($appName, $context, $appDir)
21
    {
22
        $appMeta = new AppMeta($appName, $context, $appDir);
23
        $injector = new AppInjector($appName, $context);
24
        $cache = $injector->getInstance(Cache::class);
25
        $reader = $injector->getInstance(AnnotationReader::class);
26
        /* @var $reader \Doctrine\Common\Annotations\Reader */
27
28
        // create DI factory class and AOP compiled class for all resources and save $app cache.
29
        (new Bootstrap)->newApp($appMeta, $context, $cache);
30
31
        // check resource injection and create annotation cache
32
        foreach ($appMeta->getResourceListGenerator() as list($class)) {
33
            $injector->getInstance($class);
34
            $refClass = new \ReflectionClass($class);
35
            $reader->getClassAnnotations($refClass);
36
            $methods = (new \ReflectionClass($refClass))->getMethods();
37
            foreach ($methods as $method) {
38
                $reader->getMethodAnnotations($method);
39
            }
40
        }
41
    }
42
}
43