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
|
|
|
|