1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/nnx-framework/doctrine |
4
|
|
|
* @author Malofeykin Andrey <[email protected]> |
5
|
|
|
*/ |
6
|
|
|
namespace Nnx\Doctrine\Options; |
7
|
|
|
|
8
|
|
|
use Zend\Stdlib\AbstractOptions; |
9
|
|
|
use Nnx\ModuleOptions\ModuleOptionsInterface; |
|
|
|
|
10
|
|
|
use Nnx\Doctrine\Options\ModuleOptionsInterface as CurrentModuleOptionsInterface; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class ModuleOptions |
15
|
|
|
* |
16
|
|
|
* @package Nnx\Doctrine\Options |
17
|
|
|
*/ |
18
|
|
|
class ModuleOptions extends AbstractOptions implements ModuleOptionsInterface, CurrentModuleOptionsInterface |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Строка, используемая как разделитель в полном имени класса сущности(или интерфейса), которая разделяет неймспейс |
22
|
|
|
* на две части: 1) Нейсмпейс в котором расположенные все сущности 2) Постфикс указывающий на кокнетную сущность. |
23
|
|
|
* Например \Nnx\Doctrine\PhpUnit\TestData\EntityAutoResolve\TestModule1\Entity\TestEntity\TestEntityInterface |
24
|
|
|
* 1) Разделителем будет \Entity\ |
25
|
|
|
* 2) Неймспейс в котром расположены все сущности будет \Nnx\Doctrine\PhpUnit\TestData\EntityAutoResolve\TestModule1\Entity\ |
26
|
|
|
* 3) Постфикс указывающий на кокнетную сущность будет TestEntity\TestEntityInterface |
27
|
|
|
* |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $entitySeparator; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Паттерн по которому из имени интерфейса можно получить строку, являющеюся заготовкой для формирования имени сущности |
34
|
|
|
* |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
protected $entityBodyNamePattern; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Строка которая добавляется перед заготовкой имени сущности полученной в результате |
41
|
|
|
* примерения @see \Nnx\Doctrine\Options\ModuleOptions::$entityBodyNamePattern к имени интерфейса. |
42
|
|
|
* |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
protected $entityNamePrefix; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Строка которая добавляется после заготовки имени сущности полученной в результате примерения |
49
|
|
|
* @see \Nnx\Doctrine\Options\ModuleOptions::$entityBodyNamePattern к имени интерфейса. |
50
|
|
|
* |
51
|
|
|
* @var string |
52
|
|
|
*/ |
53
|
|
|
protected $entityNamePostfix; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Имя сервиса, позволяющего получить объект кеша из модуля doctrine/cache |
57
|
|
|
* |
58
|
|
|
* (@see https://github.com/doctrine/DoctrineModule) |
59
|
|
|
* (@see vendor/doctrine/doctrine-module/config/module.config.php) |
60
|
|
|
* (@see \DoctrineModule\Service\CacheFactory) |
61
|
|
|
* |
62
|
|
|
* @var string |
63
|
|
|
*/ |
64
|
|
|
protected $entityMapDoctrineCache; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Префикс используемы для генерации ключа кеширования карты сущностей doctrine |
68
|
|
|
* |
69
|
|
|
* @var string |
70
|
|
|
*/ |
71
|
|
|
protected $entityMapDoctrineCachePrefix; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Имя сервиса, позволяющего получить объект кеша из модуля doctrine/cache для кеширования метаданных сущности |
75
|
|
|
* |
76
|
|
|
* (@see https://github.com/doctrine/DoctrineModule) |
77
|
|
|
* (@see vendor/doctrine/doctrine-module/config/module.config.php) |
78
|
|
|
* (@see \DoctrineModule\Service\CacheFactory) |
79
|
|
|
* |
80
|
|
|
* @var string |
81
|
|
|
*/ |
82
|
|
|
protected $metadataReaderCache; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Флаг определяет, нужно ли автоматически собирать кеш карты сущностей |
86
|
|
|
* |
87
|
|
|
* @var boolean |
88
|
|
|
*/ |
89
|
|
|
protected $flagAutoBuildEntityMapDoctrineCache = true; |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Список EntityManager'ов, для которых никогда не нужно собирать кеш entityMap в автоматическом режими |
93
|
|
|
* |
94
|
|
|
* @var array |
95
|
|
|
*/ |
96
|
|
|
protected $excludeEntityManagerForAutoBuildEntityMap = []; |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Флаг позволяет отключить использования кеширования при работе с entityMap |
100
|
|
|
* |
101
|
|
|
* @var bool |
102
|
|
|
*/ |
103
|
|
|
protected $flagDisableUseEntityMapDoctrineCache = false; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Настройки необходимые для создания экземпляра \Nnx\Doctrine\ManagerRegistry\ManagerRegistry |
107
|
|
|
* |
108
|
|
|
* @var ManagerRegistryOptions |
109
|
|
|
*/ |
110
|
|
|
protected $managerRegistry; |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Строка, используемая как разделитель в полном имени класса сущности (@see \Nnx\Doctrine\Options\ModuleOptions::$entitySeparator) |
114
|
|
|
* |
115
|
|
|
* @return string |
116
|
|
|
*/ |
117
|
|
|
public function getEntitySeparator() |
118
|
|
|
{ |
119
|
|
|
return $this->entitySeparator; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Устанавливает строку используемую как разделитель в полном имени класса сущности (@see \Nnx\Doctrine\Options\ModuleOptions::$entitySeparator) |
124
|
|
|
* |
125
|
|
|
* @param string $entitySeparator |
126
|
|
|
* |
127
|
|
|
* @return $this |
128
|
|
|
*/ |
129
|
|
|
public function setEntitySeparator($entitySeparator) |
130
|
|
|
{ |
131
|
|
|
$this->entitySeparator = $entitySeparator; |
132
|
|
|
|
133
|
|
|
return $this; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @inheritdoc |
138
|
|
|
* |
139
|
|
|
* @return string |
140
|
|
|
*/ |
141
|
|
|
public function getEntityBodyNamePattern() |
142
|
|
|
{ |
143
|
|
|
return $this->entityBodyNamePattern; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Устанавливает паттерн по которому из имени интерфейса можно получить строку, |
148
|
|
|
* являющеюся заготовкой для формирования имени сущности |
149
|
|
|
* |
150
|
|
|
* @param string $entityBodyNamePattern |
151
|
|
|
* |
152
|
|
|
* @return $this |
153
|
|
|
*/ |
154
|
|
|
public function setEntityBodyNamePattern($entityBodyNamePattern) |
155
|
|
|
{ |
156
|
|
|
$this->entityBodyNamePattern = $entityBodyNamePattern; |
157
|
|
|
|
158
|
|
|
return $this; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @inheritdoc |
163
|
|
|
* |
164
|
|
|
* @return string |
165
|
|
|
*/ |
166
|
|
|
public function getEntityNamePrefix() |
167
|
|
|
{ |
168
|
|
|
return $this->entityNamePrefix; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Устанавливает строку которая добавляется перед заготовкой именем сущности полученной в результате |
173
|
|
|
* примерения @see \Nnx\Doctrine\Options\ModuleOptions::$entityBodyNamePattern к имени интерфейса. |
174
|
|
|
* |
175
|
|
|
* @param string $entityNamePrefix |
176
|
|
|
* |
177
|
|
|
* @return $this |
178
|
|
|
*/ |
179
|
|
|
public function setEntityNamePrefix($entityNamePrefix) |
180
|
|
|
{ |
181
|
|
|
$this->entityNamePrefix = $entityNamePrefix; |
182
|
|
|
|
183
|
|
|
return $this; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @inheritdoc |
188
|
|
|
* |
189
|
|
|
* @return string |
190
|
|
|
*/ |
191
|
|
|
public function getEntityNamePostfix() |
192
|
|
|
{ |
193
|
|
|
return $this->entityNamePostfix; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* Устанавливает строку которая добавляется после заготовки имени сущности полученной в результате примерения |
198
|
|
|
* @see \Nnx\Doctrine\Options\ModuleOptions::$entityBodyNamePattern к имени интерфейса. |
199
|
|
|
* |
200
|
|
|
* @param string $entityNamePostfix |
201
|
|
|
* |
202
|
|
|
* @return $this |
203
|
|
|
*/ |
204
|
|
|
public function setEntityNamePostfix($entityNamePostfix) |
205
|
|
|
{ |
206
|
|
|
$this->entityNamePostfix = $entityNamePostfix; |
207
|
|
|
|
208
|
|
|
return $this; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* Возвращает имя сервиса, позволяющего получить объект кеша из модуля doctrine/cache |
213
|
|
|
* |
214
|
|
|
* @return string |
215
|
|
|
*/ |
216
|
|
|
public function getEntityMapDoctrineCache() |
217
|
|
|
{ |
218
|
|
|
return $this->entityMapDoctrineCache; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* Устанавливает имя сервиса, позволяющего получить объект кеша из модуля doctrine/cache |
223
|
|
|
* |
224
|
|
|
* @param string $entityMapDoctrineCache |
225
|
|
|
* |
226
|
|
|
* @return $this |
227
|
|
|
*/ |
228
|
|
|
public function setEntityMapDoctrineCache($entityMapDoctrineCache) |
229
|
|
|
{ |
230
|
|
|
$this->entityMapDoctrineCache = $entityMapDoctrineCache; |
231
|
|
|
|
232
|
|
|
return $this; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* Возвращает префикс используемы для генерации ключа кеширования карты сущностей doctrine |
237
|
|
|
* |
238
|
|
|
* @return string |
239
|
|
|
*/ |
240
|
|
|
public function getEntityMapDoctrineCachePrefix() |
241
|
|
|
{ |
242
|
|
|
return $this->entityMapDoctrineCachePrefix; |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* Возвращает префикс используемы для генерации ключа кеширования карты сущностей doctrine |
247
|
|
|
* |
248
|
|
|
* @param string $entityMapDoctrineCachePrefix |
249
|
|
|
* |
250
|
|
|
* @return $this |
251
|
|
|
*/ |
252
|
|
|
public function setEntityMapDoctrineCachePrefix($entityMapDoctrineCachePrefix) |
253
|
|
|
{ |
254
|
|
|
$this->entityMapDoctrineCachePrefix = $entityMapDoctrineCachePrefix; |
255
|
|
|
|
256
|
|
|
return $this; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* @inheritdoc |
261
|
|
|
* |
262
|
|
|
* @return string |
263
|
|
|
*/ |
264
|
|
|
public function getMetadataReaderCache() |
265
|
|
|
{ |
266
|
|
|
return $this->metadataReaderCache; |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* Устанавливает имя сервиса, позволяющего получить объект кеша из модуля doctrine/cache для кеширования метаданных сущности |
271
|
|
|
* |
272
|
|
|
* @param string $metadataReaderCache |
273
|
|
|
* |
274
|
|
|
* @return $this |
275
|
|
|
*/ |
276
|
|
|
public function setMetadataReaderCache($metadataReaderCache) |
277
|
|
|
{ |
278
|
|
|
$this->metadataReaderCache = $metadataReaderCache; |
279
|
|
|
|
280
|
|
|
return $this; |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* @inheritdoc |
285
|
|
|
* |
286
|
|
|
* @return boolean |
287
|
|
|
*/ |
288
|
|
|
public function getFlagAutoBuildEntityMapDoctrineCache() |
289
|
|
|
{ |
290
|
|
|
return $this->flagAutoBuildEntityMapDoctrineCache; |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
/** |
294
|
|
|
* Устанавливает флаг определяющий, нужно ли автоматически собирать кеш карты сущностей |
295
|
|
|
* |
296
|
|
|
* @param bool $flagAutoBuildEntityMapDoctrineCache |
297
|
|
|
* |
298
|
|
|
* @return $this |
299
|
|
|
*/ |
300
|
|
|
public function setFlagAutoBuildEntityMapDoctrineCache($flagAutoBuildEntityMapDoctrineCache) |
301
|
|
|
{ |
302
|
|
|
$this->flagAutoBuildEntityMapDoctrineCache = $flagAutoBuildEntityMapDoctrineCache; |
303
|
|
|
|
304
|
|
|
return $this; |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
/** |
308
|
|
|
* @inheritdoc |
309
|
|
|
* |
310
|
|
|
* @return array |
311
|
|
|
*/ |
312
|
|
|
public function getExcludeEntityManagerForAutoBuildEntityMap() |
313
|
|
|
{ |
314
|
|
|
return $this->excludeEntityManagerForAutoBuildEntityMap; |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
/** |
318
|
|
|
* Устанавливает список EntityManager'ов, для которых никогда не нужно собирать кеш entityMap в автоматическом режими |
319
|
|
|
* |
320
|
|
|
* @param array $excludeEntityManagerForAutoBuildEntityMap |
321
|
|
|
* |
322
|
|
|
* @return $this |
323
|
|
|
*/ |
324
|
|
|
public function setExcludeEntityManagerForAutoBuildEntityMap(array $excludeEntityManagerForAutoBuildEntityMap = []) |
325
|
|
|
{ |
326
|
|
|
$this->excludeEntityManagerForAutoBuildEntityMap = $excludeEntityManagerForAutoBuildEntityMap; |
327
|
|
|
|
328
|
|
|
return $this; |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
/** |
332
|
|
|
* @inheritdoc |
333
|
|
|
* |
334
|
|
|
* @return boolean |
335
|
|
|
*/ |
336
|
|
|
public function getFlagDisableUseEntityMapDoctrineCache() |
337
|
|
|
{ |
338
|
|
|
return $this->flagDisableUseEntityMapDoctrineCache; |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
/** |
342
|
|
|
* @inheritdoc |
343
|
|
|
* |
344
|
|
|
* @param boolean $flagDisableUseEntityMapDoctrineCache |
345
|
|
|
* |
346
|
|
|
* @return $this |
347
|
|
|
*/ |
348
|
|
|
public function setFlagDisableUseEntityMapDoctrineCache($flagDisableUseEntityMapDoctrineCache) |
349
|
|
|
{ |
350
|
|
|
$this->flagDisableUseEntityMapDoctrineCache = $flagDisableUseEntityMapDoctrineCache; |
351
|
|
|
|
352
|
|
|
return $this; |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
/** |
356
|
|
|
* Возвращает настройки необходимые для создания экземпляра \Nnx\Doctrine\ManagerRegistry\ManagerRegistry |
357
|
|
|
* |
358
|
|
|
* @return ManagerRegistryOptions |
359
|
|
|
*/ |
360
|
|
|
public function getManagerRegistry() |
361
|
|
|
{ |
362
|
|
|
return $this->managerRegistry; |
363
|
|
|
} |
364
|
|
|
|
365
|
|
|
/** |
366
|
|
|
* Устанавливает настройки необходимые для создания экземпляра \Nnx\Doctrine\ManagerRegistry\ManagerRegistry |
367
|
|
|
* |
368
|
|
|
* @param array $managerRegistry |
369
|
|
|
* |
370
|
|
|
* @return $this |
371
|
|
|
*/ |
372
|
|
|
public function setManagerRegistry(array $managerRegistry = []) |
373
|
|
|
{ |
374
|
|
|
$this->managerRegistry = new ManagerRegistryOptions($managerRegistry); |
375
|
|
|
|
376
|
|
|
return $this; |
377
|
|
|
} |
378
|
|
|
} |
379
|
|
|
|
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: