|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace BEAR\Package\Compiler; |
|
6
|
|
|
|
|
7
|
|
|
use BEAR\AppMeta\AbstractAppMeta; |
|
8
|
|
|
use BEAR\Resource\NamedParameterInterface; |
|
9
|
|
|
use BEAR\Sunday\Extension\Application\AppInterface; |
|
10
|
|
|
use Doctrine\Common\Annotations\Reader; |
|
11
|
|
|
use Ray\Di\InjectorInterface; |
|
12
|
|
|
|
|
13
|
|
|
use function assert; |
|
14
|
|
|
|
|
15
|
|
|
final class CompileDiScripts |
|
16
|
|
|
{ |
|
17
|
|
|
public function __construct( |
|
18
|
|
|
private CompileClassMetaInfo $compilerScanClass, |
|
19
|
|
|
private InjectorInterface $injector, |
|
20
|
|
|
) { |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function __invoke(AbstractAppMeta $appMeta): void |
|
24
|
|
|
{ |
|
25
|
|
|
$reader = $this->injector->getInstance(Reader::class); |
|
26
|
|
|
assert($reader instanceof Reader); |
|
27
|
|
|
$namedParams = $this->injector->getInstance(NamedParameterInterface::class); |
|
28
|
|
|
assert($namedParams instanceof NamedParameterInterface); |
|
29
|
|
|
// create DI factory class and AOP compiled class for all resources and save $app cache. |
|
30
|
|
|
$app = $this->injector->getInstance(AppInterface::class); |
|
31
|
|
|
assert($app instanceof AppInterface); |
|
32
|
|
|
|
|
33
|
|
|
// check resource injection and create annotation cache |
|
34
|
|
|
$metas = $appMeta->getResourceListGenerator(); |
|
35
|
|
|
foreach ($metas as $meta) { |
|
36
|
|
|
[$className] = $meta; |
|
37
|
|
|
$this->scanClass($reader, $namedParams, $className); |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Save annotation and method meta information |
|
43
|
|
|
* |
|
44
|
|
|
* @param class-string<T> $className |
|
|
|
|
|
|
45
|
|
|
* |
|
46
|
|
|
* @template T of object |
|
47
|
|
|
*/ |
|
48
|
|
|
private function scanClass(Reader $reader, NamedParameterInterface $namedParams, string $className): void |
|
49
|
|
|
{ |
|
50
|
|
|
($this->compilerScanClass)($reader, $namedParams, $className); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|