1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
|
5
|
|
|
namespace TheCodingMachine\TDBM\Commands; |
6
|
|
|
|
7
|
|
|
use Doctrine\Common\Cache\Cache; |
8
|
|
|
use Doctrine\DBAL\Connection; |
9
|
|
|
use Mouf\Database\SchemaAnalyzer\SchemaAnalyzer; |
10
|
|
|
use TheCodingMachine\TDBM\ConfigurationInterface; |
11
|
|
|
use TheCodingMachine\TDBM\Utils\Annotation\AnnotationParser; |
12
|
|
|
use TheCodingMachine\TDBM\Utils\CodeGeneratorListenerInterface; |
13
|
|
|
use TheCodingMachine\TDBM\Utils\GeneratorListenerInterface; |
14
|
|
|
use TheCodingMachine\TDBM\Utils\NamingStrategyInterface; |
15
|
|
|
use TheCodingMachine\TDBM\Utils\PathFinder\PathFinderInterface; |
16
|
|
|
use Psr\Log\LoggerInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* A class to alter any ConfigurationInterface on the fly. |
20
|
|
|
* |
21
|
|
|
* The logger can be altered with setLogger method. |
22
|
|
|
* Useful to dynamically register a logger in the Symfony commands. |
23
|
|
|
*/ |
24
|
|
|
class AlteredConfiguration implements ConfigurationInterface |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var ConfigurationInterface |
28
|
|
|
*/ |
29
|
|
|
private $configuration; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var LoggerInterface|null |
33
|
|
|
*/ |
34
|
|
|
private $logger; |
35
|
|
|
|
36
|
|
|
public function __construct(ConfigurationInterface $configuration) |
37
|
|
|
{ |
38
|
|
|
$this->configuration = $configuration; |
39
|
|
|
$this->logger = $configuration->getLogger(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return string |
45
|
|
|
*/ |
46
|
|
|
public function getBeanNamespace(): string |
47
|
|
|
{ |
48
|
|
|
return $this->configuration->getBeanNamespace(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return string |
53
|
|
|
*/ |
54
|
|
|
public function getDaoNamespace(): string |
55
|
|
|
{ |
56
|
|
|
return $this->configuration->getDaoNamespace(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return Connection |
61
|
|
|
*/ |
62
|
|
|
public function getConnection(): Connection |
63
|
|
|
{ |
64
|
|
|
return $this->configuration->getConnection(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return Cache |
69
|
|
|
*/ |
70
|
|
|
public function getCache(): Cache |
71
|
|
|
{ |
72
|
|
|
return $this->configuration->getCache(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return NamingStrategyInterface |
77
|
|
|
*/ |
78
|
|
|
public function getNamingStrategy(): NamingStrategyInterface |
79
|
|
|
{ |
80
|
|
|
return $this->configuration->getNamingStrategy(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return SchemaAnalyzer |
85
|
|
|
*/ |
86
|
|
|
public function getSchemaAnalyzer(): SchemaAnalyzer |
87
|
|
|
{ |
88
|
|
|
return $this->configuration->getSchemaAnalyzer(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return LoggerInterface|null |
93
|
|
|
*/ |
94
|
|
|
public function getLogger(): ?LoggerInterface |
95
|
|
|
{ |
96
|
|
|
return $this->logger; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return GeneratorListenerInterface |
101
|
|
|
*/ |
102
|
|
|
public function getGeneratorEventDispatcher(): GeneratorListenerInterface |
103
|
|
|
{ |
104
|
|
|
return $this->configuration->getGeneratorEventDispatcher(); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return CodeGeneratorListenerInterface |
109
|
|
|
*/ |
110
|
|
|
public function getCodeGeneratorListener(): CodeGeneratorListenerInterface |
111
|
|
|
{ |
112
|
|
|
return $this->configuration->getCodeGeneratorListener(); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param LoggerInterface $logger |
117
|
|
|
*/ |
118
|
|
|
public function setLogger(LoggerInterface $logger): void |
119
|
|
|
{ |
120
|
|
|
$this->logger = $logger; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Returns a class able to find the place of a PHP file based on the class name. |
125
|
|
|
* Useful to find the path where DAOs and beans should be written to. |
126
|
|
|
* |
127
|
|
|
* @return PathFinderInterface |
128
|
|
|
*/ |
129
|
|
|
public function getPathFinder(): PathFinderInterface |
130
|
|
|
{ |
131
|
|
|
return $this->configuration->getPathFinder(); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @return AnnotationParser |
136
|
|
|
*/ |
137
|
|
|
public function getAnnotationParser(): AnnotationParser |
138
|
|
|
{ |
139
|
|
|
return $this->configuration->getAnnotationParser(); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function getLockFilePath(): string |
143
|
|
|
{ |
144
|
|
|
return $this->configuration->getLockFilePath(); |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|