Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like DoctrineExtension often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use DoctrineExtension, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
36 | class DoctrineExtension extends AbstractDoctrineExtension |
||
37 | { |
||
38 | /** @var string */ |
||
39 | private $defaultConnection; |
||
40 | |||
41 | /** |
||
42 | * {@inheritDoc} |
||
43 | */ |
||
44 | public function load(array $configs, ContainerBuilder $container) |
||
45 | { |
||
46 | $configuration = $this->getConfiguration($configs, $container); |
||
47 | $config = $this->processConfiguration($configuration, $configs); |
||
|
|||
48 | |||
49 | if (! empty($config['dbal'])) { |
||
50 | $this->dbalLoad($config['dbal'], $container); |
||
51 | |||
52 | $this->loadMessengerServices($container); |
||
53 | } |
||
54 | |||
55 | if (empty($config['orm'])) { |
||
56 | return; |
||
57 | } |
||
58 | |||
59 | if (empty($config['dbal'])) { |
||
60 | throw new LogicException('Configuring the ORM layer requires to configure the DBAL layer as well.'); |
||
61 | } |
||
62 | |||
63 | $this->ormLoad($config['orm'], $container); |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * Loads the DBAL configuration. |
||
68 | * |
||
69 | * Usage example: |
||
70 | * |
||
71 | * <doctrine:dbal id="myconn" dbname="sfweb" user="root" /> |
||
72 | * |
||
73 | * @param array $config An array of configuration settings |
||
74 | * @param ContainerBuilder $container A ContainerBuilder instance |
||
75 | */ |
||
76 | protected function dbalLoad(array $config, ContainerBuilder $container) |
||
77 | { |
||
78 | $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
||
79 | $loader->load('dbal.xml'); |
||
80 | |||
81 | if (empty($config['default_connection'])) { |
||
82 | $keys = array_keys($config['connections']); |
||
83 | $config['default_connection'] = reset($keys); |
||
84 | } |
||
85 | |||
86 | $this->defaultConnection = $config['default_connection']; |
||
87 | |||
88 | $container->setAlias('database_connection', sprintf('doctrine.dbal.%s_connection', $this->defaultConnection)); |
||
89 | $container->getAlias('database_connection')->setPublic(true); |
||
90 | $container->setAlias('doctrine.dbal.event_manager', new Alias(sprintf('doctrine.dbal.%s_connection.event_manager', $this->defaultConnection), false)); |
||
91 | |||
92 | $container->setParameter('doctrine.dbal.connection_factory.types', $config['types']); |
||
93 | |||
94 | $connections = []; |
||
95 | |||
96 | foreach (array_keys($config['connections']) as $name) { |
||
97 | $connections[$name] = sprintf('doctrine.dbal.%s_connection', $name); |
||
98 | } |
||
99 | |||
100 | $container->setParameter('doctrine.connections', $connections); |
||
101 | $container->setParameter('doctrine.default_connection', $this->defaultConnection); |
||
102 | |||
103 | foreach ($config['connections'] as $name => $connection) { |
||
104 | $this->loadDbalConnection($name, $connection, $container); |
||
105 | } |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * Loads a configured DBAL connection. |
||
110 | * |
||
111 | * @param string $name The name of the connection |
||
112 | * @param array $connection A dbal connection configuration. |
||
113 | * @param ContainerBuilder $container A ContainerBuilder instance |
||
114 | */ |
||
115 | protected function loadDbalConnection($name, array $connection, ContainerBuilder $container) |
||
116 | { |
||
117 | $configuration = $container->setDefinition(sprintf('doctrine.dbal.%s_connection.configuration', $name), new ChildDefinition('doctrine.dbal.connection.configuration')); |
||
118 | $logger = null; |
||
119 | if ($connection['logging']) { |
||
120 | $logger = new Reference('doctrine.dbal.logger'); |
||
121 | } |
||
122 | unset($connection['logging']); |
||
123 | |||
124 | if ($connection['profiling']) { |
||
125 | $profilingAbstractId = $connection['profiling_collect_backtrace'] ? |
||
126 | 'doctrine.dbal.logger.backtrace' : |
||
127 | 'doctrine.dbal.logger.profiling'; |
||
128 | |||
129 | $profilingLoggerId = $profilingAbstractId . '.' . $name; |
||
130 | $container->setDefinition($profilingLoggerId, new ChildDefinition($profilingAbstractId)); |
||
131 | $profilingLogger = new Reference($profilingLoggerId); |
||
132 | $container->getDefinition('data_collector.doctrine') |
||
133 | ->addMethodCall('addLogger', [$name, $profilingLogger]) |
||
134 | ->replaceArgument(1, $connection['profiling_collect_schema_errors']); |
||
135 | |||
136 | if ($logger !== null) { |
||
137 | $chainLogger = new ChildDefinition('doctrine.dbal.logger.chain'); |
||
138 | $chainLogger->addMethodCall('addLogger', [$profilingLogger]); |
||
139 | |||
140 | $loggerId = 'doctrine.dbal.logger.chain.' . $name; |
||
141 | $container->setDefinition($loggerId, $chainLogger); |
||
142 | $logger = new Reference($loggerId); |
||
143 | } else { |
||
144 | $logger = $profilingLogger; |
||
145 | } |
||
146 | } |
||
147 | unset( |
||
148 | $connection['profiling'], |
||
149 | $connection['profiling_collect_backtrace'], |
||
150 | $connection['profiling_collect_schema_errors'] |
||
151 | ); |
||
152 | |||
153 | if (isset($connection['auto_commit'])) { |
||
154 | $configuration->addMethodCall('setAutoCommit', [$connection['auto_commit']]); |
||
155 | } |
||
156 | |||
157 | unset($connection['auto_commit']); |
||
158 | |||
159 | if (isset($connection['schema_filter']) && $connection['schema_filter']) { |
||
160 | $definition = new Definition(RegexSchemaAssetFilter::class, [$connection['schema_filter']]); |
||
161 | $definition->addTag('doctrine.dbal.schema_filter', ['connection' => $name]); |
||
162 | $container->setDefinition(sprintf('doctrine.dbal.%s_regex_schema_filter', $name), $definition); |
||
163 | } |
||
164 | |||
165 | unset($connection['schema_filter']); |
||
166 | |||
167 | if ($logger) { |
||
168 | $configuration->addMethodCall('setSQLLogger', [$logger]); |
||
169 | } |
||
170 | |||
171 | // event manager |
||
172 | $container->setDefinition(sprintf('doctrine.dbal.%s_connection.event_manager', $name), new ChildDefinition('doctrine.dbal.connection.event_manager')); |
||
173 | |||
174 | // connection |
||
175 | $options = $this->getConnectionOptions($connection); |
||
176 | |||
177 | $def = $container |
||
178 | ->setDefinition(sprintf('doctrine.dbal.%s_connection', $name), new ChildDefinition('doctrine.dbal.connection')) |
||
179 | ->setPublic(true) |
||
180 | ->setArguments([ |
||
181 | $options, |
||
182 | new Reference(sprintf('doctrine.dbal.%s_connection.configuration', $name)), |
||
183 | new Reference(sprintf('doctrine.dbal.%s_connection.event_manager', $name)), |
||
184 | $connection['mapping_types'], |
||
185 | ]); |
||
186 | |||
187 | // Set class in case "wrapper_class" option was used to assist IDEs |
||
188 | if (isset($options['wrapperClass'])) { |
||
189 | $def->setClass($options['wrapperClass']); |
||
190 | } |
||
191 | |||
192 | if (! empty($connection['use_savepoints'])) { |
||
193 | $def->addMethodCall('setNestTransactionsWithSavepoints', [$connection['use_savepoints']]); |
||
194 | } |
||
195 | |||
196 | // Create a shard_manager for this connection |
||
197 | if (! isset($options['shards'])) { |
||
198 | return; |
||
199 | } |
||
200 | |||
201 | $shardManagerDefinition = new Definition($options['shardManagerClass'], [new Reference(sprintf('doctrine.dbal.%s_connection', $name))]); |
||
202 | $container->setDefinition(sprintf('doctrine.dbal.%s_shard_manager', $name), $shardManagerDefinition); |
||
203 | } |
||
204 | |||
205 | protected function getConnectionOptions($connection) |
||
206 | { |
||
207 | $options = $connection; |
||
208 | |||
209 | if (isset($options['platform_service'])) { |
||
210 | $options['platform'] = new Reference($options['platform_service']); |
||
211 | unset($options['platform_service']); |
||
212 | } |
||
213 | unset($options['mapping_types']); |
||
214 | |||
215 | if (isset($options['shard_choser_service'])) { |
||
216 | $options['shard_choser'] = new Reference($options['shard_choser_service']); |
||
217 | unset($options['shard_choser_service']); |
||
218 | } |
||
219 | |||
220 | foreach ([ |
||
221 | 'options' => 'driverOptions', |
||
222 | 'driver_class' => 'driverClass', |
||
223 | 'wrapper_class' => 'wrapperClass', |
||
224 | 'keep_slave' => 'keepSlave', |
||
225 | 'shard_choser' => 'shardChoser', |
||
226 | 'shard_manager_class' => 'shardManagerClass', |
||
227 | 'server_version' => 'serverVersion', |
||
228 | 'default_table_options' => 'defaultTableOptions', |
||
229 | ] as $old => $new) { |
||
230 | if (! isset($options[$old])) { |
||
231 | continue; |
||
232 | } |
||
233 | |||
234 | $options[$new] = $options[$old]; |
||
235 | unset($options[$old]); |
||
236 | } |
||
237 | |||
238 | if (! empty($options['slaves']) && ! empty($options['shards'])) { |
||
239 | throw new InvalidArgumentException('Sharding and master-slave connection cannot be used together'); |
||
240 | } |
||
241 | |||
242 | if (! empty($options['slaves'])) { |
||
243 | $nonRewrittenKeys = [ |
||
244 | 'driver' => true, |
||
245 | 'driverOptions' => true, |
||
246 | 'driverClass' => true, |
||
247 | 'wrapperClass' => true, |
||
248 | 'keepSlave' => true, |
||
249 | 'shardChoser' => true, |
||
250 | 'platform' => true, |
||
251 | 'slaves' => true, |
||
252 | 'master' => true, |
||
253 | 'shards' => true, |
||
254 | 'serverVersion' => true, |
||
255 | 'defaultTableOptions' => true, |
||
256 | // included by safety but should have been unset already |
||
257 | 'logging' => true, |
||
258 | 'profiling' => true, |
||
259 | 'mapping_types' => true, |
||
260 | 'platform_service' => true, |
||
261 | ]; |
||
262 | View Code Duplication | foreach ($options as $key => $value) { |
|
263 | if (isset($nonRewrittenKeys[$key])) { |
||
264 | continue; |
||
265 | } |
||
266 | $options['master'][$key] = $value; |
||
267 | unset($options[$key]); |
||
268 | } |
||
269 | if (empty($options['wrapperClass'])) { |
||
270 | // Change the wrapper class only if the user does not already forced using a custom one. |
||
271 | $options['wrapperClass'] = 'Doctrine\\DBAL\\Connections\\MasterSlaveConnection'; |
||
272 | } |
||
273 | } else { |
||
274 | unset($options['slaves']); |
||
275 | } |
||
276 | |||
277 | if (! empty($options['shards'])) { |
||
278 | $nonRewrittenKeys = [ |
||
279 | 'driver' => true, |
||
280 | 'driverOptions' => true, |
||
281 | 'driverClass' => true, |
||
282 | 'wrapperClass' => true, |
||
283 | 'keepSlave' => true, |
||
284 | 'shardChoser' => true, |
||
285 | 'platform' => true, |
||
286 | 'slaves' => true, |
||
287 | 'global' => true, |
||
288 | 'shards' => true, |
||
289 | 'serverVersion' => true, |
||
290 | 'defaultTableOptions' => true, |
||
291 | // included by safety but should have been unset already |
||
292 | 'logging' => true, |
||
293 | 'profiling' => true, |
||
294 | 'mapping_types' => true, |
||
295 | 'platform_service' => true, |
||
296 | ]; |
||
297 | View Code Duplication | foreach ($options as $key => $value) { |
|
298 | if (isset($nonRewrittenKeys[$key])) { |
||
299 | continue; |
||
300 | } |
||
301 | $options['global'][$key] = $value; |
||
302 | unset($options[$key]); |
||
303 | } |
||
304 | if (empty($options['wrapperClass'])) { |
||
305 | // Change the wrapper class only if the user does not already forced using a custom one. |
||
306 | $options['wrapperClass'] = 'Doctrine\\DBAL\\Sharding\\PoolingShardConnection'; |
||
307 | } |
||
308 | if (empty($options['shardManagerClass'])) { |
||
309 | // Change the shard manager class only if the user does not already forced using a custom one. |
||
310 | $options['shardManagerClass'] = 'Doctrine\\DBAL\\Sharding\\PoolingShardManager'; |
||
311 | } |
||
312 | } else { |
||
313 | unset($options['shards']); |
||
314 | } |
||
315 | |||
316 | return $options; |
||
317 | } |
||
318 | |||
319 | /** |
||
320 | * Loads the Doctrine ORM configuration. |
||
321 | * |
||
322 | * Usage example: |
||
323 | * |
||
324 | * <doctrine:orm id="mydm" connection="myconn" /> |
||
325 | * |
||
326 | * @param array $config An array of configuration settings |
||
327 | * @param ContainerBuilder $container A ContainerBuilder instance |
||
328 | */ |
||
329 | protected function ormLoad(array $config, ContainerBuilder $container) |
||
330 | { |
||
331 | if (! class_exists(UnitOfWork::class)) { |
||
332 | throw new LogicException('To configure the ORM layer, you must first install the doctrine/orm package.'); |
||
333 | } |
||
334 | |||
335 | $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
||
336 | $loader->load('orm.xml'); |
||
337 | |||
338 | if (class_exists(AbstractType::class)) { |
||
339 | $container->getDefinition('form.type.entity')->addTag('kernel.reset', ['method' => 'reset']); |
||
340 | } |
||
341 | |||
342 | $entityManagers = []; |
||
343 | foreach (array_keys($config['entity_managers']) as $name) { |
||
344 | $entityManagers[$name] = sprintf('doctrine.orm.%s_entity_manager', $name); |
||
345 | } |
||
346 | $container->setParameter('doctrine.entity_managers', $entityManagers); |
||
347 | |||
348 | if (empty($config['default_entity_manager'])) { |
||
349 | $tmp = array_keys($entityManagers); |
||
350 | $config['default_entity_manager'] = reset($tmp); |
||
351 | } |
||
352 | $container->setParameter('doctrine.default_entity_manager', $config['default_entity_manager']); |
||
353 | |||
354 | $options = ['auto_generate_proxy_classes', 'proxy_dir', 'proxy_namespace']; |
||
355 | foreach ($options as $key) { |
||
356 | $container->setParameter('doctrine.orm.' . $key, $config[$key]); |
||
357 | } |
||
358 | |||
359 | $container->setAlias('doctrine.orm.entity_manager', sprintf('doctrine.orm.%s_entity_manager', $config['default_entity_manager'])); |
||
360 | $container->getAlias('doctrine.orm.entity_manager')->setPublic(true); |
||
361 | |||
362 | $config['entity_managers'] = $this->fixManagersAutoMappings($config['entity_managers'], $container->getParameter('kernel.bundles')); |
||
363 | |||
364 | foreach ($config['entity_managers'] as $name => $entityManager) { |
||
365 | $entityManager['name'] = $name; |
||
366 | $this->loadOrmEntityManager($entityManager, $container); |
||
367 | |||
368 | if (interface_exists(PropertyInfoExtractorInterface::class)) { |
||
369 | $this->loadPropertyInfoExtractor($name, $container); |
||
370 | } |
||
371 | |||
372 | $this->loadValidatorLoader($name, $container); |
||
373 | } |
||
374 | |||
375 | if ($config['resolve_target_entities']) { |
||
376 | $def = $container->findDefinition('doctrine.orm.listeners.resolve_target_entity'); |
||
377 | foreach ($config['resolve_target_entities'] as $name => $implementation) { |
||
378 | $def->addMethodCall('addResolveTargetEntity', [ |
||
379 | $name, |
||
380 | $implementation, |
||
381 | [], |
||
382 | ]); |
||
383 | } |
||
384 | |||
385 | $def->addTag('doctrine.event_subscriber'); |
||
386 | } |
||
387 | |||
388 | $container->registerForAutoconfiguration(ServiceEntityRepositoryInterface::class) |
||
389 | ->addTag(ServiceRepositoryCompilerPass::REPOSITORY_SERVICE_TAG); |
||
390 | |||
391 | $container->registerForAutoconfiguration(EventSubscriberInterface::class) |
||
392 | ->addTag('doctrine.event_subscriber'); |
||
393 | } |
||
394 | |||
395 | /** |
||
396 | * Loads a configured ORM entity manager. |
||
397 | * |
||
398 | * @param array $entityManager A configured ORM entity manager. |
||
399 | * @param ContainerBuilder $container A ContainerBuilder instance |
||
400 | */ |
||
401 | protected function loadOrmEntityManager(array $entityManager, ContainerBuilder $container) |
||
531 | |||
532 | /** |
||
533 | * Loads an ORM entity managers bundle mapping information. |
||
534 | * |
||
535 | * There are two distinct configuration possibilities for mapping information: |
||
536 | * |
||
537 | * 1. Specify a bundle and optionally details where the entity and mapping information reside. |
||
538 | * 2. Specify an arbitrary mapping location. |
||
539 | * |
||
540 | * @param array $entityManager A configured ORM entity manager |
||
541 | * @param Definition $ormConfigDef A Definition instance |
||
542 | * @param ContainerBuilder $container A ContainerBuilder instance |
||
543 | * |
||
544 | * @example |
||
545 | * |
||
546 | * doctrine.orm: |
||
547 | * mappings: |
||
548 | * MyBundle1: ~ |
||
549 | * MyBundle2: yml |
||
550 | * MyBundle3: { type: annotation, dir: Entities/ } |
||
551 | * MyBundle4: { type: xml, dir: Resources/config/doctrine/mapping } |
||
552 | * MyBundle5: |
||
553 | * type: yml |
||
554 | * dir: bundle-mappings/ |
||
555 | * alias: BundleAlias |
||
556 | * arbitrary_key: |
||
557 | * type: xml |
||
558 | * dir: %kernel.project_dir%/src/vendor/DoctrineExtensions/lib/DoctrineExtensions/Entities |
||
559 | * prefix: DoctrineExtensions\Entities\ |
||
560 | * alias: DExt |
||
561 | * |
||
562 | * In the case of bundles everything is really optional (which leads to autodetection for this bundle) but |
||
563 | * in the mappings key everything except alias is a required argument. |
||
564 | */ |
||
565 | protected function loadOrmEntityManagerMappingInformation(array $entityManager, Definition $ormConfigDef, ContainerBuilder $container) |
||
576 | |||
577 | /** |
||
578 | * Loads an ORM second level cache bundle mapping information. |
||
579 | * |
||
580 | * @param array $entityManager A configured ORM entity manager |
||
581 | * @param Definition $ormConfigDef A Definition instance |
||
582 | * @param ContainerBuilder $container A ContainerBuilder instance |
||
583 | * |
||
584 | * @example |
||
585 | * entity_managers: |
||
586 | * default: |
||
587 | * second_level_cache: |
||
588 | * region_cache_driver: apc |
||
589 | * log_enabled: true |
||
590 | * regions: |
||
591 | * my_service_region: |
||
592 | * type: service |
||
593 | * service : "my_service_region" |
||
594 | * |
||
595 | * my_query_region: |
||
596 | * lifetime: 300 |
||
597 | * cache_driver: array |
||
598 | * type: filelock |
||
599 | * |
||
600 | * my_entity_region: |
||
601 | * lifetime: 600 |
||
602 | * cache_driver: |
||
603 | * type: apc |
||
604 | */ |
||
605 | protected function loadOrmSecondLevelCache(array $entityManager, Definition $ormConfigDef, ContainerBuilder $container) |
||
693 | |||
694 | /** |
||
695 | * {@inheritDoc} |
||
696 | */ |
||
697 | protected function getObjectManagerElementName($name) : string |
||
701 | |||
702 | protected function getMappingObjectDefaultName() : string |
||
706 | |||
707 | /** |
||
708 | * {@inheritDoc} |
||
709 | */ |
||
710 | protected function getMappingResourceConfigDirectory() : string |
||
714 | |||
715 | /** |
||
716 | * {@inheritDoc} |
||
717 | */ |
||
718 | protected function getMappingResourceExtension() : string |
||
722 | |||
723 | /** |
||
724 | * {@inheritDoc} |
||
725 | */ |
||
726 | protected function loadCacheDriver($cacheName, $objectManagerName, array $cacheDriver, ContainerBuilder $container) : string |
||
727 | { |
||
728 | $serviceId = null; |
||
729 | $aliasId = $this->getObjectManagerElementName(sprintf('%s_%s', $objectManagerName, $cacheName)); |
||
730 | |||
731 | switch ($cacheDriver['type'] ?? 'pool') { |
||
732 | case 'service': |
||
733 | $serviceId = $cacheDriver['id']; |
||
734 | break; |
||
735 | |||
736 | case 'pool': |
||
737 | $serviceId = $this->createPoolCacheDefinition($container, $cacheDriver['pool'] ?? $this->createArrayAdapterCachePool($container, $objectManagerName, $cacheName)); |
||
738 | break; |
||
739 | |||
740 | default: |
||
741 | throw new \InvalidArgumentException(sprintf( |
||
742 | 'Unknown cache of type "%s" configured for cache "%s" in entity manager "%s".', |
||
743 | $cacheDriver['type'], |
||
744 | $cacheName, |
||
745 | $objectManagerName |
||
746 | )); |
||
747 | } |
||
748 | |||
749 | $container->setAlias($aliasId, new Alias($serviceId, false)); |
||
750 | |||
751 | return $aliasId; |
||
752 | } |
||
753 | |||
754 | /** |
||
755 | * Loads a configured entity managers cache drivers. |
||
756 | * |
||
757 | * @param array $entityManager A configured ORM entity manager. |
||
758 | * @param ContainerBuilder $container A ContainerBuilder instance |
||
759 | */ |
||
760 | protected function loadOrmCacheDrivers(array $entityManager, ContainerBuilder $container) |
||
766 | |||
767 | /** |
||
768 | * Loads a property info extractor for each defined entity manager. |
||
769 | */ |
||
770 | private function loadPropertyInfoExtractor(string $entityManagerName, ContainerBuilder $container) : void |
||
771 | { |
||
772 | $propertyExtractorDefinition = $container->register(sprintf('doctrine.orm.%s_entity_manager.property_info_extractor', $entityManagerName), DoctrineExtractor::class); |
||
773 | $argumentId = sprintf('doctrine.orm.%s_entity_manager', $entityManagerName); |
||
774 | |||
775 | $propertyExtractorDefinition->addArgument(new Reference($argumentId)); |
||
776 | |||
777 | $propertyExtractorDefinition->addTag('property_info.list_extractor', ['priority' => -1001]); |
||
778 | $propertyExtractorDefinition->addTag('property_info.type_extractor', ['priority' => -999]); |
||
779 | $propertyExtractorDefinition->addTag('property_info.access_extractor', ['priority' => -999]); |
||
780 | } |
||
781 | |||
782 | /** |
||
783 | * Loads a validator loader for each defined entity manager. |
||
784 | */ |
||
785 | private function loadValidatorLoader(string $entityManagerName, ContainerBuilder $container) : void |
||
786 | { |
||
787 | $validatorLoaderDefinition = $container->register(sprintf('doctrine.orm.%s_entity_manager.validator_loader', $entityManagerName), DoctrineLoader::class); |
||
788 | $validatorLoaderDefinition->addArgument(new Reference(sprintf('doctrine.orm.%s_entity_manager', $entityManagerName))); |
||
789 | |||
790 | $validatorLoaderDefinition->addTag('validator.auto_mapper', ['priority' => -100]); |
||
791 | } |
||
792 | |||
793 | /** |
||
794 | * @param array $objectManager |
||
795 | * @param string $cacheName |
||
796 | */ |
||
797 | public function loadObjectManagerCacheDriver(array $objectManager, ContainerBuilder $container, $cacheName) |
||
798 | { |
||
799 | $this->loadCacheDriver($cacheName, $objectManager['name'], $objectManager[$cacheName . '_driver'], $container); |
||
800 | } |
||
801 | |||
802 | /** |
||
803 | * {@inheritDoc} |
||
804 | */ |
||
805 | public function getXsdValidationBasePath() : string |
||
806 | { |
||
807 | return __DIR__ . '/../Resources/config/schema'; |
||
808 | } |
||
809 | |||
810 | /** |
||
811 | * {@inheritDoc} |
||
812 | */ |
||
813 | public function getNamespace() : string |
||
814 | { |
||
815 | return 'http://symfony.com/schema/dic/doctrine'; |
||
816 | } |
||
817 | |||
818 | /** |
||
819 | * {@inheritDoc} |
||
820 | */ |
||
821 | public function getConfiguration(array $config, ContainerBuilder $container) : Configuration |
||
822 | { |
||
823 | return new Configuration($container->getParameter('kernel.debug')); |
||
824 | } |
||
825 | |||
826 | protected function getMetadataDriverClass(string $driverType) : string |
||
827 | { |
||
828 | return '%' . $this->getObjectManagerElementName('metadata.' . $driverType . '.class%'); |
||
829 | } |
||
830 | |||
831 | private function loadMessengerServices(ContainerBuilder $container) : void |
||
832 | { |
||
833 | // If the Messenger component is installed and the doctrine transaction middleware is available, wire it: |
||
834 | if (! interface_exists(MessageBusInterface::class) || ! class_exists(DoctrineTransactionMiddleware::class)) { |
||
835 | return; |
||
836 | } |
||
837 | |||
838 | $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
||
839 | $loader->load('messenger.xml'); |
||
840 | |||
841 | if (! class_exists(DoctrineClearEntityManagerWorkerSubscriber::class)) { |
||
842 | $container->removeDefinition('doctrine.orm.messenger.event_subscriber.doctrine_clear_entity_manager'); |
||
843 | } |
||
844 | |||
845 | $transportFactoryDefinition = $container->getDefinition('messenger.transport.doctrine.factory'); |
||
846 | if (! class_exists(DoctrineTransportFactory::class)) { |
||
847 | // If symfony/messenger < 5.1 |
||
848 | if (! class_exists(\Symfony\Component\Messenger\Transport\Doctrine\DoctrineTransportFactory::class)) { |
||
849 | // Dont add the tag |
||
850 | return; |
||
851 | } |
||
852 | |||
853 | $transportFactoryDefinition->setClass(\Symfony\Component\Messenger\Transport\Doctrine\DoctrineTransportFactory::class); |
||
854 | } |
||
855 | |||
856 | $transportFactoryDefinition->addTag('messenger.transport_factory'); |
||
857 | } |
||
858 | |||
859 | private function createPoolCacheDefinition(ContainerBuilder $container, string $poolName) : string |
||
869 | |||
870 | private function createArrayAdapterCachePool(ContainerBuilder $container, string $objectManagerName, string $cacheName) : string |
||
880 | } |
||
881 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: