1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Portiny\Doctrine\Adapter\Nette\DI; |
6
|
|
|
|
7
|
|
|
use Doctrine\Common\Cache\ArrayCache; |
8
|
|
|
use Doctrine\Common\Cache\Cache; |
9
|
|
|
use Doctrine\Common\Cache\RedisCache; |
10
|
|
|
use Doctrine\Common\EventManager; |
11
|
|
|
use Doctrine\Common\EventSubscriber; |
12
|
|
|
use Doctrine\DBAL\Connection; |
13
|
|
|
use Doctrine\DBAL\Tools\Console\Command\ImportCommand; |
14
|
|
|
use Doctrine\ORM\Cache\CacheConfiguration; |
15
|
|
|
use Doctrine\ORM\Cache\CacheFactory; |
16
|
|
|
use Doctrine\ORM\Cache\DefaultCacheFactory; |
17
|
|
|
use Doctrine\ORM\Cache\Logging\CacheLogger; |
18
|
|
|
use Doctrine\ORM\Cache\Logging\CacheLoggerChain; |
19
|
|
|
use Doctrine\ORM\Cache\Logging\StatisticsCacheLogger; |
20
|
|
|
use Doctrine\ORM\Cache\RegionsConfiguration; |
21
|
|
|
use Doctrine\ORM\Configuration; |
22
|
|
|
use Doctrine\ORM\EntityManager; |
23
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
24
|
|
|
use Doctrine\ORM\EntityRepository; |
25
|
|
|
use Doctrine\ORM\Events; |
26
|
|
|
use Doctrine\ORM\Mapping\UnderscoreNamingStrategy; |
27
|
|
|
use Doctrine\ORM\Query\Filter\SQLFilter; |
28
|
|
|
use Doctrine\ORM\Tools\Console\Command\ClearCache\MetadataCommand; |
29
|
|
|
use Doctrine\ORM\Tools\Console\Command\ClearCache\QueryCommand; |
30
|
|
|
use Doctrine\ORM\Tools\Console\Command\ClearCache\ResultCommand; |
31
|
|
|
use Doctrine\ORM\Tools\Console\Command\ConvertMappingCommand; |
32
|
|
|
use Doctrine\ORM\Tools\Console\Command\GenerateEntitiesCommand; |
33
|
|
|
use Doctrine\ORM\Tools\Console\Command\GenerateProxiesCommand; |
34
|
|
|
use Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand; |
35
|
|
|
use Doctrine\ORM\Tools\Console\Command\SchemaTool\DropCommand; |
36
|
|
|
use Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand; |
37
|
|
|
use Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand; |
38
|
|
|
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper; |
39
|
|
|
use Doctrine\ORM\Tools\ResolveTargetEntityListener; |
40
|
|
|
use Nette\DI\CompilerExtension; |
41
|
|
|
use Nette\DI\ContainerBuilder; |
42
|
|
|
use Nette\DI\ServiceDefinition; |
43
|
|
|
use Nette\DI\Statement; |
44
|
|
|
use Nette\PhpGenerator\ClassType; |
45
|
|
|
use Nette\Utils\AssertionException; |
46
|
|
|
use Nette\Utils\Validators; |
47
|
|
|
use Portiny\Console\Adapter\Nette\DI\ConsoleExtension; |
48
|
|
|
use Portiny\Doctrine\Adapter\Nette\Tracy\DoctrineSQLPanel; |
49
|
|
|
use Portiny\Doctrine\Cache\DefaultCache; |
50
|
|
|
use Portiny\Doctrine\Contract\Provider\ClassMappingProviderInterface; |
51
|
|
|
use Portiny\Doctrine\Contract\Provider\EntitySourceProviderInterface; |
52
|
|
|
use Redis; |
53
|
|
|
use Symfony\Component\Console\Helper\HelperSet; |
54
|
|
|
use Tracy\IBarPanel; |
55
|
|
|
|
56
|
|
|
class DoctrineExtension extends CompilerExtension |
57
|
|
|
{ |
58
|
|
|
/** |
59
|
|
|
* @var string |
60
|
|
|
*/ |
61
|
|
|
private const DOCTRINE_SQL_PANEL = DoctrineSQLPanel::class; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @var array |
65
|
|
|
*/ |
66
|
|
|
private static $defaults = [ |
67
|
|
|
'debug' => '%debugMode%', |
68
|
|
|
'dbal' => [ |
69
|
|
|
'type_overrides' => [], |
70
|
|
|
'types' => [], |
71
|
|
|
'schema_filter' => NULL, |
72
|
|
|
], |
73
|
|
|
'prefix' => 'doctrine.default', |
74
|
|
|
'proxyDir' => '%tempDir%/cache/proxies', |
75
|
|
|
'sourceDir' => NULL, |
76
|
|
|
'entityManagerClassName' => EntityManager::class, |
77
|
|
|
'defaultRepositoryClassName' => EntityRepository::class, |
78
|
|
|
'repositoryFactory' => NULL, |
79
|
|
|
'namingStrategy' => UnderscoreNamingStrategy::class, |
80
|
|
|
'sqlLogger' => NULL, |
81
|
|
|
'targetEntityMappings' => [], |
82
|
|
|
'metadata' => [], |
83
|
|
|
'functions' => [], |
84
|
|
|
// caches |
85
|
|
|
'metadataCache' => 'default', |
86
|
|
|
'queryCache' => 'default', |
87
|
|
|
'resultCache' => 'default', |
88
|
|
|
'hydrationCache' => 'default', |
89
|
|
|
'secondLevelCache' => [ |
90
|
|
|
'enabled' => FALSE, |
91
|
|
|
'factoryClass' => DefaultCacheFactory::class, |
92
|
|
|
'driver' => 'default', |
93
|
|
|
'regions' => [ |
94
|
|
|
'defaultLifetime' => 3600, |
95
|
|
|
'defaultLockLifetime' => 60, |
96
|
|
|
], |
97
|
|
|
'fileLockRegionDirectory' => '%tempDir%/cache/Doctrine.Cache.Locks', |
98
|
|
|
'logging' => '%debugMode%', |
99
|
|
|
], |
100
|
|
|
'cache' => [ |
101
|
|
|
'redis' => [], |
102
|
|
|
], |
103
|
|
|
]; |
104
|
|
|
|
105
|
|
|
private $entitySources = []; |
106
|
|
|
|
107
|
|
|
private $classMappings = []; |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* {@inheritdoc} |
111
|
|
|
*/ |
112
|
1 |
|
public function loadConfiguration(): void |
113
|
|
|
{ |
114
|
1 |
|
$config = $this->parseConfig(); |
115
|
|
|
|
116
|
1 |
|
$builder = $this->getContainerBuilder(); |
117
|
1 |
|
$name = $config['prefix']; |
118
|
|
|
|
119
|
1 |
|
$configurationDefinition = $builder->addDefinition($name . '.config') |
120
|
1 |
|
->setType(Configuration::class) |
121
|
1 |
|
->addSetup('setFilterSchemaAssetsExpression', [$config['dbal']['schema_filter']]) |
122
|
1 |
|
->addSetup('setDefaultRepositoryClassName', [$config['defaultRepositoryClassName']]); |
123
|
|
|
|
124
|
1 |
|
if ($config['repositoryFactory']) { |
125
|
|
|
$builder->addDefinition($name . '.repositoryFactory') |
126
|
|
|
->setClass($config['repositoryFactory']); |
127
|
|
|
$configurationDefinition->addSetup('setRepositoryFactory', ['@' . $name . '.repositoryFactory']); |
128
|
|
|
} |
129
|
1 |
|
if ($config['sqlLogger']) { |
130
|
|
|
$builder->addDefinition($name . '.sqlLogger') |
131
|
|
|
->setClass($config['sqlLogger']); |
132
|
|
|
$configurationDefinition->addSetup('setSQLLogger', ['@' . $name . '.sqlLogger']); |
133
|
|
|
} |
134
|
|
|
|
135
|
1 |
|
if ($config['metadataCache'] !== FALSE) { |
136
|
1 |
|
$configurationDefinition->addSetup( |
137
|
1 |
|
'setMetadataCacheImpl', |
138
|
1 |
|
[$this->getCache($name . '.metadata', $builder, $config['metadataCache'])] |
139
|
|
|
); |
140
|
|
|
} |
141
|
|
|
|
142
|
1 |
|
if ($config['queryCache'] !== FALSE) { |
143
|
1 |
|
$configurationDefinition->addSetup( |
144
|
1 |
|
'setQueryCacheImpl', |
145
|
1 |
|
[$this->getCache($name . '.query', $builder, $config['queryCache'])] |
146
|
|
|
); |
147
|
|
|
} |
148
|
|
|
|
149
|
1 |
|
if ($config['resultCache'] !== FALSE) { |
150
|
1 |
|
$configurationDefinition->addSetup( |
151
|
1 |
|
'setResultCacheImpl', |
152
|
1 |
|
[$this->getCache($name . '.ormResult', $builder, $config['resultCache'])] |
153
|
|
|
); |
154
|
|
|
} |
155
|
|
|
|
156
|
1 |
|
if ($config['hydrationCache'] !== FALSE) { |
157
|
1 |
|
$configurationDefinition->addSetup( |
158
|
1 |
|
'setHydrationCacheImpl', |
159
|
1 |
|
[$this->getCache($name . '.hydration', $builder, $config['hydrationCache'])] |
160
|
|
|
); |
161
|
|
|
} |
162
|
|
|
|
163
|
1 |
|
$this->processSecondLevelCache($name, $config['secondLevelCache']); |
164
|
|
|
|
165
|
1 |
|
$builder->addDefinition($name . '.connection') |
166
|
1 |
|
->setType(Connection::class) |
167
|
1 |
|
->setFactory('@' . $name . '.entityManager::getConnection'); |
168
|
|
|
|
169
|
1 |
|
$builder->addDefinition($name . '.entityManager') |
170
|
1 |
|
->setType($config['entityManagerClassName']) |
171
|
1 |
|
->setFactory( |
172
|
1 |
|
$config['entityManagerClassName'] . '::create', |
173
|
1 |
|
[$config['connection'], '@' . $name . '.config', '@Doctrine\Common\EventManager'] |
174
|
|
|
); |
175
|
|
|
|
176
|
1 |
|
$builder->addDefinition($name . '.namingStrategy') |
177
|
1 |
|
->setType($config['namingStrategy']); |
178
|
|
|
|
179
|
1 |
|
$builder->addDefinition($name . '.resolver') |
180
|
1 |
|
->setType(ResolveTargetEntityListener::class); |
181
|
|
|
|
182
|
1 |
|
if ($this->hasIBarPanelInterface()) { |
183
|
1 |
|
$builder->addDefinition($this->prefix($name . '.diagnosticsPanel')) |
184
|
1 |
|
->setType(self::DOCTRINE_SQL_PANEL); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
// import Doctrine commands into Portiny/Console if exists |
188
|
1 |
|
$this->registerCommandsIntoConsole($builder, $name); |
189
|
1 |
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* {@inheritdoc} |
193
|
|
|
*/ |
194
|
1 |
|
public function beforeCompile(): void |
195
|
|
|
{ |
196
|
1 |
|
$config = $this->getConfig(self::$defaults); |
197
|
1 |
|
$name = $config['prefix']; |
198
|
|
|
|
199
|
1 |
|
$builder = $this->getContainerBuilder(); |
200
|
|
|
|
201
|
1 |
|
$configDefinition = $builder->getDefinition($name . '.config') |
202
|
1 |
|
->setFactory( |
203
|
1 |
|
'\Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration', |
204
|
1 |
|
[array_values($this->entitySources), $config['debug'], $config['proxyDir'], NULL, FALSE] |
205
|
|
|
) |
206
|
1 |
|
->addSetup('setNamingStrategy', ['@' . $name . '.namingStrategy']); |
207
|
|
|
|
208
|
1 |
|
foreach ($config['functions'] as $functionName => $function) { |
209
|
1 |
|
$configDefinition->addSetup('addCustomStringFunction', [$functionName, $function]); |
210
|
|
|
} |
211
|
|
|
|
212
|
1 |
|
foreach ($this->classMappings as $source => $target) { |
213
|
|
|
$builder->getDefinition($name . '.resolver') |
214
|
|
|
->addSetup('addResolveTargetEntity', [$source, $target, []]); |
215
|
|
|
} |
216
|
|
|
|
217
|
1 |
|
$this->processDbalTypes($name, $config['dbal']['types']); |
218
|
1 |
|
$this->processDbalTypeOverrides($name, $config['dbal']['type_overrides']); |
219
|
1 |
|
$this->processEventSubscribers($name); |
220
|
1 |
|
$this->processFilters($name); |
221
|
1 |
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* {@inheritdoc} |
225
|
|
|
*/ |
226
|
1 |
|
public function afterCompile(ClassType $classType): void |
227
|
|
|
{ |
228
|
1 |
|
$initialize = $classType->methods['initialize']; |
229
|
1 |
|
if ($this->hasIBarPanelInterface()) { |
230
|
1 |
|
$initialize->addBody('$this->getByType(\'' . self::DOCTRINE_SQL_PANEL . '\')->bindToBar();'); |
231
|
|
|
} |
232
|
|
|
|
233
|
1 |
|
$initialize->addBody( |
234
|
1 |
|
'$filterCollection = $this->getByType(\'' . EntityManagerInterface::class . '\')->getFilters();' |
235
|
|
|
); |
236
|
1 |
|
$builder = $this->getContainerBuilder(); |
237
|
1 |
|
foreach ($builder->findByType(SQLFilter::class) as $name => $filterDefinition) { |
238
|
|
|
$initialize->addBody('$filterCollection->enable(\'' . $name . '\');'); |
239
|
|
|
} |
240
|
1 |
|
} |
241
|
|
|
|
242
|
1 |
|
protected function processSecondLevelCache($name, array $config): void |
243
|
|
|
{ |
244
|
1 |
|
if (! $config['enabled']) { |
245
|
1 |
|
return; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
$builder = $this->getContainerBuilder(); |
249
|
|
|
|
250
|
|
|
$cacheService = $this->getCache($name . '.secondLevel', $builder, $config['driver']); |
251
|
|
|
|
252
|
|
|
$builder->addDefinition($this->prefix($name . '.cacheFactory')) |
253
|
|
|
->setType(CacheFactory::class) |
254
|
|
|
->setFactory($config['factoryClass'], [ |
255
|
|
|
$this->prefix('@' . $name . '.cacheRegionsConfiguration'), |
256
|
|
|
$cacheService, |
257
|
|
|
]) |
258
|
|
|
->addSetup('setFileLockRegionDirectory', [$config['fileLockRegionDirectory']]); |
259
|
|
|
|
260
|
|
|
$builder->addDefinition($this->prefix($name . '.cacheRegionsConfiguration')) |
261
|
|
|
->setFactory(RegionsConfiguration::class, [ |
262
|
|
|
$config['regions']['defaultLifetime'], |
263
|
|
|
$config['regions']['defaultLockLifetime'], |
264
|
|
|
]); |
265
|
|
|
|
266
|
|
|
$logger = $builder->addDefinition($this->prefix($name . '.cacheLogger')) |
267
|
|
|
->setType(CacheLogger::class) |
268
|
|
|
->setFactory(CacheLoggerChain::class) |
269
|
|
|
->setAutowired(FALSE); |
270
|
|
|
|
271
|
|
|
if ($config['logging']) { |
272
|
|
|
$logger->addSetup('setLogger', ['statistics', new Statement(StatisticsCacheLogger::class)]); |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
$cacheConfigName = $this->prefix($name . '.ormCacheConfiguration'); |
276
|
|
|
$builder->addDefinition($cacheConfigName) |
277
|
|
|
->setType(CacheConfiguration::class) |
278
|
|
|
->addSetup('setCacheFactory', [$this->prefix('@' . $name . '.cacheFactory')]) |
279
|
|
|
->addSetup('setCacheLogger', [$this->prefix('@' . $name . '.cacheLogger')]) |
280
|
|
|
->setAutowired(FALSE); |
281
|
|
|
|
282
|
|
|
$configuration = $builder->getDefinitionByType(Configuration::class); |
283
|
|
|
$configuration->addSetup('setSecondLevelCacheEnabled'); |
284
|
|
|
$configuration->addSetup('setSecondLevelCacheConfiguration', ['@' . $cacheConfigName]); |
285
|
|
|
} |
286
|
|
|
|
287
|
1 |
|
private function getCache(string $prefix, ContainerBuilder $containerBuilder, string $cacheType): string |
288
|
|
|
{ |
289
|
1 |
|
$cacheServiceName = $containerBuilder->getByType(Cache::class); |
290
|
1 |
|
if ($cacheServiceName !== NULL && strlen($cacheServiceName) > 0) { |
291
|
1 |
|
return '@' . $cacheServiceName; |
292
|
|
|
} |
293
|
|
|
|
294
|
1 |
|
$cacheClass = ArrayCache::class; |
295
|
1 |
|
if ($cacheType) { |
296
|
|
|
switch ($cacheType) { |
297
|
1 |
|
case 'redis': |
298
|
|
|
$cacheClass = RedisCache::class; |
299
|
|
|
break; |
300
|
|
|
|
301
|
1 |
|
case 'default': |
302
|
|
|
default: |
303
|
1 |
|
$cacheClass = DefaultCache::class; |
304
|
1 |
|
break; |
305
|
|
|
} |
306
|
|
|
} |
307
|
|
|
|
308
|
1 |
|
$cacheDefinition = $containerBuilder->addDefinition($prefix . '.cache') |
309
|
1 |
|
->setType($cacheClass); |
310
|
|
|
|
311
|
1 |
|
if ($cacheType === 'redis') { |
312
|
|
|
$config = $this->parseConfig(); |
313
|
|
|
$redisConfig = $config['cache']['redis']; |
314
|
|
|
|
315
|
|
|
$containerBuilder->addDefinition($prefix . '.redis') |
316
|
|
|
->setType(Redis::class) |
317
|
|
|
->setAutowired(FALSE) |
318
|
|
|
->addSetup('connect', [ |
319
|
|
|
$redisConfig['host'] ?? '127.0.0.1', |
320
|
|
|
$redisConfig['port'] ?? null, |
321
|
|
|
$redisConfig['timeout'] ?? 0.0, |
322
|
|
|
$redisConfig['reserved'] ?? null, |
323
|
|
|
$redisConfig['retryInterval'] ?? 0, |
324
|
|
|
]) |
325
|
|
|
->addSetup('select', [$redisConfig['database'] ?? 1]); |
326
|
|
|
|
327
|
|
|
$cacheDefinition->addSetup('setRedis', ['@' . $prefix . '.redis']); |
328
|
|
|
} |
329
|
|
|
|
330
|
1 |
|
return '@' . $prefix . '.cache'; |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
/** |
334
|
|
|
* @throws AssertionException |
335
|
|
|
*/ |
336
|
1 |
|
private function parseConfig(): array |
337
|
|
|
{ |
338
|
1 |
|
$config = $this->getConfig(self::$defaults); |
339
|
1 |
|
$this->classMappings = $config['targetEntityMappings']; |
340
|
1 |
|
$this->entitySources = $config['metadata']; |
341
|
|
|
|
342
|
1 |
|
foreach ($this->compiler->getExtensions() as $extension) { |
343
|
1 |
|
if ($extension instanceof ClassMappingProviderInterface) { |
344
|
|
|
$entityMapping = $extension->getClassMapping(); |
345
|
|
|
Validators::assert($entityMapping, 'array'); |
346
|
|
|
$this->classMappings = array_merge($this->classMappings, $entityMapping); |
347
|
|
|
} |
348
|
|
|
|
349
|
1 |
|
if ($extension instanceof EntitySourceProviderInterface) { |
350
|
|
|
$entitySource = $extension->getEntitySource(); |
351
|
|
|
Validators::assert($entitySource, 'array'); |
352
|
1 |
|
$this->entitySources = array_merge($this->entitySources, $entitySource); |
353
|
|
|
} |
354
|
|
|
} |
355
|
|
|
|
356
|
1 |
|
if ($config['sourceDir']) { |
357
|
|
|
$this->entitySources[] = $config['sourceDir']; |
358
|
|
|
} |
359
|
|
|
|
360
|
1 |
|
return $config; |
361
|
|
|
} |
362
|
|
|
|
363
|
1 |
|
private function hasIBarPanelInterface(): bool |
364
|
|
|
{ |
365
|
1 |
|
return interface_exists(IBarPanel::class); |
366
|
|
|
} |
367
|
|
|
|
368
|
1 |
|
private function hasPortinyConsole(): bool |
369
|
|
|
{ |
370
|
1 |
|
return class_exists(ConsoleExtension::class); |
371
|
|
|
} |
372
|
|
|
|
373
|
1 |
|
private function hasEventManager(ContainerBuilder $containerBuilder): bool |
374
|
|
|
{ |
375
|
1 |
|
$eventManagerServiceName = $containerBuilder->getByType(EventManager::class); |
376
|
1 |
|
return $eventManagerServiceName !== NULL && strlen($eventManagerServiceName) > 0; |
377
|
|
|
} |
378
|
|
|
|
379
|
1 |
|
private function processDbalTypes(string $name, array $types): void |
380
|
|
|
{ |
381
|
1 |
|
$builder = $this->getContainerBuilder(); |
382
|
1 |
|
$entityManagerDefinition = $builder->getDefinition($name . '.entityManager'); |
383
|
|
|
|
384
|
1 |
|
foreach ($types as $type => $className) { |
385
|
1 |
|
$entityManagerDefinition->addSetup( |
386
|
1 |
|
'if ( ! Doctrine\DBAL\Types\Type::hasType(?)) { Doctrine\DBAL\Types\Type::addType(?, ?); }', |
387
|
1 |
|
[$type, $type, $className] |
388
|
|
|
); |
389
|
|
|
} |
390
|
1 |
|
} |
391
|
|
|
|
392
|
1 |
|
private function processDbalTypeOverrides(string $name, array $types): void |
393
|
|
|
{ |
394
|
1 |
|
$builder = $this->getContainerBuilder(); |
395
|
1 |
|
$entityManagerDefinition = $builder->getDefinition($name . '.entityManager'); |
396
|
|
|
|
397
|
1 |
|
foreach ($types as $type => $className) { |
398
|
1 |
|
$entityManagerDefinition->addSetup('Doctrine\DBAL\Types\Type::overrideType(?, ?);', [$type, $className]); |
399
|
|
|
} |
400
|
1 |
|
} |
401
|
|
|
|
402
|
1 |
|
private function processEventSubscribers(string $name): void |
403
|
|
|
{ |
404
|
1 |
|
$builder = $this->getContainerBuilder(); |
405
|
|
|
|
406
|
1 |
|
if ($this->hasEventManager($builder)) { |
407
|
|
|
$eventManagerDefinition = $builder->getDefinition($builder->getByType(EventManager::class)) |
408
|
|
|
->addSetup('addEventListener', [Events::loadClassMetadata, '@' . $name . '.resolver']); |
409
|
|
|
} else { |
410
|
1 |
|
$eventManagerDefinition = $builder->addDefinition($name . '.eventManager') |
411
|
1 |
|
->setType(EventManager::class) |
412
|
1 |
|
->addSetup('addEventListener', [Events::loadClassMetadata, '@' . $name . '.resolver']); |
413
|
|
|
} |
414
|
|
|
|
415
|
1 |
|
foreach (array_keys($builder->findByType(EventSubscriber::class)) as $serviceName) { |
416
|
1 |
|
$eventManagerDefinition->addSetup('addEventSubscriber', ['@' . $serviceName]); |
417
|
|
|
} |
418
|
1 |
|
} |
419
|
|
|
|
420
|
1 |
|
private function processFilters(string $name): void |
421
|
|
|
{ |
422
|
1 |
|
$builder = $this->getContainerBuilder(); |
423
|
|
|
|
424
|
1 |
|
$configurationService = $builder->getDefinitionByType(Configuration::class); |
425
|
1 |
|
foreach ($builder->findByType(SQLFilter::class) as $name => $filterDefinition) { |
426
|
|
|
$configurationService->addSetup('addFilter', [$name, $filterDefinition->getType()]); |
427
|
|
|
} |
428
|
1 |
|
} |
429
|
|
|
|
430
|
1 |
|
private function registerCommandsIntoConsole(ContainerBuilder $containerBuilder, string $name): void |
431
|
|
|
{ |
432
|
1 |
|
if ($this->hasPortinyConsole()) { |
433
|
|
|
$commands = [ |
434
|
|
|
ConvertMappingCommand::class, |
435
|
|
|
CreateCommand::class, |
436
|
|
|
DropCommand::class, |
437
|
|
|
GenerateEntitiesCommand::class, |
438
|
|
|
GenerateProxiesCommand::class, |
439
|
|
|
ImportCommand::class, |
440
|
|
|
MetadataCommand::class, |
441
|
|
|
QueryCommand::class, |
442
|
|
|
ResultCommand::class, |
443
|
|
|
UpdateCommand::class, |
444
|
|
|
ValidateSchemaCommand::class, |
445
|
|
|
]; |
446
|
|
|
foreach ($commands as $index => $command) { |
447
|
|
|
$containerBuilder->addDefinition($name . '.command.' . $index) |
448
|
|
|
->setType($command); |
449
|
|
|
} |
450
|
|
|
|
451
|
|
|
$helperSets = $containerBuilder->findByType(HelperSet::class); |
452
|
|
|
if ($helperSets) { |
453
|
|
|
/** @var ServiceDefinition $helperSet */ |
454
|
|
|
$helperSet = reset($helperSets); |
455
|
|
|
$helperSet->addSetup('set', [new Statement(EntityManagerHelper::class), 'em']); |
456
|
|
|
} |
457
|
|
|
} |
458
|
1 |
|
} |
459
|
|
|
} |
460
|
|
|
|