1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BrainExe\Core\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use BrainExe\Annotations\Annotations\Service; |
6
|
|
|
use BrainExe\Annotations\Loader; |
7
|
|
|
use BrainExe\Core\Core; |
8
|
|
|
use BrainExe\Core\DependencyInjection\CompilerPass\GlobalCompilerPass; |
9
|
|
|
|
10
|
|
|
use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper; |
11
|
|
|
use Symfony\Component\DependencyInjection\Container; |
12
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
13
|
|
|
use Symfony\Component\DependencyInjection\Dumper\PhpDumper; |
14
|
|
|
|
15
|
|
|
use Symfony\Component\Finder\Finder; |
16
|
|
|
use Symfony\Component\Finder\SplFileInfo; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @Service("Core.Rebuild", public=false) |
20
|
|
|
*/ |
21
|
|
|
class Rebuild |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param bool $boot |
26
|
|
|
* @return Container|ContainerBuilder |
27
|
|
|
*/ |
28
|
2 |
|
public function rebuildDIC($boot = true) |
|
|
|
|
29
|
|
|
{ |
30
|
2 |
|
$containerBuilder = new ContainerBuilder(); |
31
|
|
|
|
32
|
2 |
|
$this->readAnnotations($containerBuilder); |
33
|
|
|
|
34
|
2 |
|
$containerBuilder->addCompilerPass(new GlobalCompilerPass()); |
35
|
2 |
|
$containerBuilder->compile(); |
36
|
|
|
|
37
|
2 |
|
$this->dumpContainer($containerBuilder); |
38
|
|
|
|
39
|
2 |
|
if ($boot) { |
40
|
1 |
|
$core = new Core(); |
41
|
1 |
|
return $core->boot(); |
42
|
|
|
} |
43
|
|
|
|
44
|
1 |
|
return $containerBuilder; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param ContainerBuilder $container |
49
|
|
|
*/ |
50
|
2 |
|
protected function readAnnotations(ContainerBuilder $container) |
51
|
|
|
{ |
52
|
2 |
|
$annotationLoader = new Loader($container); |
53
|
2 |
|
$appFinder = new Finder(); |
54
|
|
|
|
55
|
2 |
|
$appFinder->directories() |
56
|
2 |
|
->in([ROOT, CORE_ROOT, BRAINEXE_VENDOR_ROOT]) |
57
|
2 |
|
->depth("<=1") |
|
|
|
|
58
|
2 |
|
->name('src'); |
59
|
|
|
|
60
|
2 |
|
$annotationLoader->load('src/'); |
61
|
2 |
|
$annotationLoader->load(CORE_ROOT); |
62
|
|
|
|
63
|
2 |
|
foreach ($appFinder as $dir) { |
64
|
|
|
/** @var SplFileInfo $dir */ |
65
|
2 |
|
$dirName = $dir->getPathname(); |
66
|
2 |
|
$annotationLoader->load($dirName); |
67
|
|
|
} |
68
|
2 |
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param ContainerBuilder $container |
72
|
|
|
*/ |
73
|
2 |
|
protected function dumpContainer(ContainerBuilder $container) |
74
|
|
|
{ |
75
|
2 |
|
$randomId = mt_rand(); |
76
|
2 |
|
$className = sprintf('dic_%d', $randomId); |
77
|
2 |
|
$containerFile = 'cache/dic.php'; |
78
|
|
|
|
79
|
2 |
|
$dumper = new PhpDumper($container); |
80
|
2 |
|
$dumper->setProxyDumper(new ProxyDumper()); |
81
|
|
|
|
82
|
2 |
|
$containerContent = $dumper->dump(['class' => $className]); |
83
|
2 |
|
file_put_contents('cache/dic.php', $containerContent); |
84
|
2 |
|
file_put_contents('cache/dic.txt', $className); |
85
|
2 |
|
@chmod($containerFile, 0777); |
|
|
|
|
86
|
|
|
|
87
|
2 |
|
$debug = $container->getParameter('debug'); |
88
|
2 |
|
file_put_contents( |
89
|
2 |
|
ROOT . 'cache/config.json', |
90
|
|
|
json_encode( |
91
|
2 |
|
$container->getParameterBag()->all(), |
92
|
2 |
|
$debug ? JSON_PRETTY_PRINT : null |
93
|
|
|
) |
94
|
|
|
); |
95
|
2 |
|
} |
96
|
|
|
} |
97
|
|
|
|
This check looks for method names that are not written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes
databaseConnectionSeeker
.