|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace SlayerBirden\DFCodeGeneration\Generator\Config; |
|
5
|
|
|
|
|
6
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
7
|
|
|
use SlayerBirden\DFCodeGeneration\Generator\GeneratorInterface; |
|
8
|
|
|
use Zend\Code\Generator\ClassGenerator; |
|
9
|
|
|
use Zend\Code\Generator\FileGenerator; |
|
10
|
|
|
use Zend\Code\Generator\MethodGenerator; |
|
11
|
|
|
|
|
12
|
|
|
class Config implements GeneratorInterface |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var DataProviderInterface |
|
16
|
|
|
*/ |
|
17
|
|
|
private $provider; |
|
18
|
|
|
|
|
19
|
3 |
|
public function __construct(DataProviderInterface $configProvider) |
|
20
|
|
|
{ |
|
21
|
3 |
|
$this->provider = $configProvider; |
|
22
|
3 |
|
} |
|
23
|
|
|
|
|
24
|
2 |
|
public function generate(): string |
|
25
|
|
|
{ |
|
26
|
|
|
$new = [ |
|
27
|
2 |
|
'\\Zend\\ServiceManager\\AbstractFactory\\ConfigAbstractFactory' => $this->getAbstractFactoryConfig(), |
|
28
|
|
|
'doctrine' => [ |
|
29
|
|
|
'paths' => [ |
|
30
|
2 |
|
$this->provider->getEntitiesSrc(), |
|
31
|
|
|
], |
|
32
|
|
|
], |
|
33
|
|
|
'dependencies' => [ |
|
34
|
|
|
'delegators' => [ |
|
35
|
|
|
'\\Zend\\Expressive\\Application' => [ |
|
36
|
2 |
|
$this->provider->getRouteFactoryName(), |
|
37
|
|
|
] |
|
38
|
|
|
] |
|
39
|
|
|
], |
|
40
|
|
|
'input_filter_specs' => [ |
|
41
|
2 |
|
$this->provider->getInputFilterName() => $this->provider->getInputFilterSpec() |
|
42
|
|
|
], |
|
43
|
|
|
]; |
|
44
|
|
|
|
|
45
|
2 |
|
$existing = $this->provider->getCurrentConfig(); |
|
46
|
2 |
|
$invoke = 'return ' . var_export(array_replace_recursive($existing, $new), true) . ';'; |
|
47
|
|
|
|
|
48
|
2 |
|
return (new FileGenerator()) |
|
49
|
2 |
|
->setNamespace($this->provider->getConfigNameSpace()) |
|
50
|
2 |
|
->setClass( |
|
51
|
2 |
|
(new ClassGenerator('ConfigProvider')) |
|
52
|
2 |
|
->addMethodFromGenerator( |
|
53
|
2 |
|
(new MethodGenerator('__invoke')) |
|
54
|
2 |
|
->setBody($invoke) |
|
55
|
|
|
) |
|
56
|
|
|
) |
|
57
|
2 |
|
->generate(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
2 |
|
private function getAbstractFactoryConfig(): array |
|
61
|
|
|
{ |
|
62
|
|
|
return [ |
|
63
|
2 |
|
$this->provider->getControllerName('add') => [ |
|
64
|
|
|
EntityManagerInterface::class, |
|
65
|
2 |
|
'\\Zend\\Hydrator\\ClassMethods', |
|
66
|
2 |
|
$this->provider->getInputFilterName(), |
|
67
|
2 |
|
'\\Psr\\Log\\LoggerInterface', |
|
68
|
2 |
|
'\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor', |
|
69
|
|
|
], |
|
70
|
2 |
|
$this->provider->getControllerName('update') => [ |
|
71
|
|
|
EntityManagerInterface::class, |
|
72
|
2 |
|
'\\Zend\\Hydrator\\ClassMethods', |
|
73
|
2 |
|
$this->provider->getInputFilterName(), |
|
74
|
2 |
|
'\\Psr\\Log\\LoggerInterface', |
|
75
|
2 |
|
'\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor', |
|
76
|
|
|
], |
|
77
|
2 |
|
$this->provider->getControllerName('get') => [ |
|
78
|
|
|
EntityManagerInterface::class, |
|
79
|
|
|
'\\Psr\\Log\\LoggerInterface', |
|
80
|
|
|
'\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor', |
|
81
|
|
|
], |
|
82
|
2 |
|
$this->provider->getControllerName('gets') => [ |
|
83
|
|
|
EntityManagerInterface::class, |
|
84
|
|
|
'\\Psr\\Log\\LoggerInterface', |
|
85
|
|
|
'\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor', |
|
86
|
|
|
], |
|
87
|
2 |
|
$this->provider->getControllerName('delete') => [ |
|
88
|
|
|
EntityManagerInterface::class, |
|
89
|
|
|
'\\Psr\\Log\\LoggerInterface', |
|
90
|
|
|
'\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor', |
|
91
|
|
|
], |
|
92
|
|
|
]; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
3 |
|
public function getClassName(): string |
|
96
|
|
|
{ |
|
97
|
3 |
|
return $this->provider->getConfigNameSpace() . '\\ConfigProvider'; |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|