Test Setup Failed
Push — master ( e168c9...58337e )
by Dominik
03:03 queued 31s
created

getOrmMappingDriverChainDefinition()   C

Complexity

Conditions 7
Paths 1

Size

Total Lines 40
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 7.049

Importance

Changes 0
Metric Value
dl 0
loc 40
ccs 18
cts 20
cp 0.9
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 21
nc 1
nop 1
crap 7.049
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * (c) Beau Simensen <[email protected]> (https://github.com/dflydev/dflydev-doctrine-orm-service-provider)
7
 */
8
9
namespace Chubbyphp\ServiceProvider;
10
11
use Doctrine\Common\Cache\ApcuCache;
12
use Doctrine\Common\Cache\ArrayCache;
13
use Doctrine\Common\Cache\CacheProvider;
14
use Doctrine\Common\Cache\FilesystemCache;
15
use Doctrine\Common\Cache\MemcacheCache;
16
use Doctrine\Common\Cache\MemcachedCache;
17
use Doctrine\Common\Cache\XcacheCache;
18
use Doctrine\Common\Cache\RedisCache;
19
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain;
20
use Doctrine\Common\Persistence\Mapping\Driver\StaticPHPDriver;
21
use Doctrine\DBAL\Types\Type;
22
use Doctrine\ORM\Cache\CacheConfiguration;
23
use Doctrine\ORM\Configuration;
24
use Doctrine\ORM\EntityManager;
25
use Doctrine\ORM\EntityRepository;
26
use Doctrine\ORM\Mapping\ClassMetadataFactory;
27
use Doctrine\ORM\Mapping\DefaultEntityListenerResolver;
28
use Doctrine\ORM\Mapping\DefaultNamingStrategy;
29
use Doctrine\ORM\Mapping\DefaultQuoteStrategy;
30
use Doctrine\ORM\Mapping\Driver\SimplifiedXmlDriver;
31
use Doctrine\ORM\Mapping\Driver\SimplifiedYamlDriver;
32
use Doctrine\ORM\Mapping\Driver\XmlDriver;
33
use Doctrine\ORM\Mapping\Driver\YamlDriver;
34
use Doctrine\ORM\Repository\DefaultRepositoryFactory;
35
use Pimple\Container;
36
use Pimple\ServiceProviderInterface;
37
38
final class DoctrineOrmServiceProvider implements ServiceProviderInterface
39
{
40
    /**
41
     * Register ORM service.
42
     *
43
     * @param Container $container
44
     */
45 2
    public function register(Container $container)
46
    {
47 2
        $container['orm.em.default_options'] = $this->getOrmEmDefaultOptions();
48 2
        $container['orm.ems.options.initializer'] = $this->getOrmEmsOptionsInitializerDefinition($container);
49 2
        $container['orm.ems'] = $this->getOrmEmsDefinition($container);
50 2
        $container['orm.ems.config'] = $this->getOrmEmsConfigServiceProvider($container);
51 2
        $container['orm.proxies_dir'] = sys_get_temp_dir();
52 2
        $container['orm.auto_generate_proxies'] = true;
53 2
        $container['orm.proxies_namespace'] = 'DoctrineProxy';
54 2
        $container['orm.mapping_driver_chain'] = $this->getOrmMappingDriverChainDefinition($container);
55 2
        $container['orm.mapping_driver_chain.factory'] = $this->getOrmMappingDriverChainFactoryDefinition($container);
56 2
        $container['orm.mapping_driver.factory.annotation'] = $this->getOrmMappingDriverFactoryAnnotation($container);
57 2
        $container['orm.mapping_driver.factory.yml'] = $this->getOrmMappingDriverFactoryYaml($container);
58 2
        $container['orm.mapping_driver.factory.simple_yml'] = $this->getOrmMappingDriverFactorySimpleYaml($container);
59 2
        $container['orm.mapping_driver.factory.xml'] = $this->getOrmMappingDriverFactoryXml($container);
60 2
        $container['orm.mapping_driver.factory.simple_xml'] = $this->getOrmMappingDriverFactorySimpleXml($container);
61 2
        $container['orm.mapping_driver.factory.php'] = $this->getOrmMappingDriverFactoryPhp($container);
62 2
        $container['orm.cache.locator'] = $this->getOrmCacheLocatorDefinition($container);
63 2
        $container['orm.cache.factory'] = $this->getOrmCacheFactoryDefinition($container);
64 2
        $container['orm.cache.factory.apcu'] = $this->getOrmCacheFactoryApcuDefinition($container);
65 2
        $container['orm.cache.factory.array'] = $this->getOrmCacheFactoryArrayDefinition($container);
66 2
        $container['orm.cache.factory.filesystem'] = $this->getOrmCacheFactoryFilesystemDefinition($container);
67 2
        $container['orm.cache.factory.memcache'] = $this->getOrmCacheFactoryMemcacheDefinition($container);
68 2
        $container['orm.cache.factory.memcached'] = $this->getOrmCacheFactoryMemcachedDefinition($container);
69 2
        $container['orm.cache.factory.redis'] = $this->getOrmCacheFactoryRedisDefinition($container);
70 2
        $container['orm.cache.factory.xcache'] = $this->getOrmCacheFactoryXCacheDefinition($container);
71 2
        $container['orm.default_cache'] = ['driver' => 'array'];
72 2
        $container['orm.custom.functions.string'] = [];
73 2
        $container['orm.custom.functions.numeric'] = [];
74 2
        $container['orm.custom.functions.datetime'] = [];
75 2
        $container['orm.custom.hydration_modes'] = [];
76 2
        $container['orm.class_metadata_factory_name'] = ClassMetadataFactory::class;
77 2
        $container['orm.default_repository_class'] = EntityRepository::class;
78 2
        $container['orm.strategy.naming'] = $this->getOrmNamingStrategyDefinition($container);
79 2
        $container['orm.strategy.quote'] = $this->getOrmQuoteStrategyDefinition($container);
80 2
        $container['orm.entity_listener_resolver'] = $this->getOrmEntityListenerResolverDefinition($container);
81 2
        $container['orm.repository_factory'] = $this->getOrmRepositoryFactoryDefinition($container);
82 2
        $container['orm.second_level_cache.enabled'] = false;
83 2
        $container['orm.second_level_cache.configuration'] = $this->getOrmSecondLevelCacheConfigurationDefinition($container);
84 2
        $container['orm.default.query_hints'] = [];
85 2
        $container['orm.em'] = $this->getOrmEmDefinition($container);
86 2
        $container['orm.em.config'] = $this->getOrmEmConfigDefinition($container);
87 2
    }
88
89
    /**
90
     * @return array
91
     */
92 2
    private function getOrmEmDefaultOptions(): array
93
    {
94
        return [
95 2
            'connection' => 'default',
96
            'mappings' => [],
97
            'types' => [],
98
        ];
99
    }
100
101
    /**
102
     * @param Container $container
103
     *
104
     * @return \Closure
105
     */
106
    private function getOrmEmsOptionsInitializerDefinition(Container $container): \Closure
107
    {
108 2
        return $container->protect(function () use ($container) {
109 2
            static $initialized = false;
110
111 2
            if ($initialized) {
112 2
                return;
113
            }
114
115 2
            $initialized = true;
116
117 2
            if (!isset($container['orm.ems.options'])) {
118 2
                $container['orm.ems.options'] = [
119 2
                    'default' => isset($container['orm.em.options']) ? $container['orm.em.options'] : [],
120
                ];
121
            }
122
123 2
            $tmp = $container['orm.ems.options'];
124 2
            foreach ($tmp as $name => &$options) {
125 2
                $options = array_replace($container['orm.em.default_options'], $options);
126
127 2
                if (!isset($container['orm.ems.default'])) {
128 2
                    $container['orm.ems.default'] = $name;
129
                }
130
            }
131
132 2
            $container['orm.ems.options'] = $tmp;
133 2
        });
134
    }
135
136
    /**
137
     * @param Container $container
138
     *
139
     * @return \Closure
140
     */
141
    private function getOrmEmsDefinition(Container $container): \Closure
142
    {
143 2
        return function () use ($container) {
144 2
            $container['orm.ems.options.initializer']();
145
146 2
            $ems = new Container();
147 2
            foreach ($container['orm.ems.options'] as $name => $options) {
148 2
                if ($container['orm.ems.default'] === $name) {
149
                    // we use shortcuts here in case the default has been overridden
150 2
                    $config = $container['orm.em.config'];
151
                } else {
152
                    $config = $container['orm.ems.config'][$name];
153
                }
154
155 2
                $ems[$name] = function () use ($container, $options, $config) {
156 2
                    return EntityManager::create(
157 2
                        $container['dbs'][$options['connection']],
158 2
                        $config,
159 2
                        $container['dbs.event_manager'][$options['connection']]
160
                    );
161 2
                };
162
            }
163
164 2
            return $ems;
165 2
        };
166
    }
167
168
    /**
169
     * @param Container $container
170
     *
171
     * @return \Closure
172
     */
173
    private function getOrmEmsConfigServiceProvider(Container $container): \Closure
174
    {
175 2
        return function () use ($container) {
176 2
            $container['orm.ems.options.initializer']();
177
178 2
            $configs = new Container();
179 2
            foreach ($container['orm.ems.options'] as $name => $options) {
180 2
                $configs[$name] = $this->getOrmEmConfigByNameAndOptionsDefinition($container, $name, $options);
181
            }
182
183 2
            return $configs;
184 2
        };
185
    }
186
187
    /**
188
     * @param Container $container
189
     * @param string    $name
190
     * @param array     $options
191
     *
192
     * @return \Closure
193
     */
194
    private function getOrmEmConfigByNameAndOptionsDefinition(
195
        Container $container,
196
        string $name,
197
        array $options
198
    ): \Closure {
199 2
        return function () use ($container, $name, $options) {
200 2
            $config = new Configuration();
201
202 2
            $config->setProxyDir($container['orm.proxies_dir']);
203 2
            $config->setAutoGenerateProxyClasses($container['orm.auto_generate_proxies']);
204 2
            $config->setProxyNamespace($container['orm.proxies_namespace']);
205
            $config->setMetadataDriverImpl(
206
                $container['orm.mapping_driver_chain']($name, $config, (array) $options['mappings'])
207 2
            );
208 2
            $config->setQueryCacheImpl($container['orm.cache.locator']($name, 'query', $options));
209 1
            $config->setHydrationCacheImpl($container['orm.cache.locator']($name, 'hydration', $options));
210
            $config->setMetadataCacheImpl($container['orm.cache.locator']($name, 'metadata', $options));
211
            $config->setResultCacheImpl($container['orm.cache.locator']($name, 'result', $options));
212
213
            foreach ((array) $options['types'] as $typeName => $typeClass) {
214
                if (Type::hasType($typeName)) {
215 1
                    Type::overrideType($typeName, $typeClass);
216
                } else {
217
                    Type::addType($typeName, $typeClass);
218
                }
219 1
            }
220 1
221
            $config->setCustomStringFunctions($container['orm.custom.functions.string']);
222
            $config->setCustomNumericFunctions($container['orm.custom.functions.numeric']);
223
            $config->setCustomDatetimeFunctions($container['orm.custom.functions.datetime']);
224
            $config->setCustomHydrationModes($container['orm.custom.hydration_modes']);
225
226 1
            $config->setClassMetadataFactoryName($container['orm.class_metadata_factory_name']);
227
            $config->setDefaultRepositoryClassName($container['orm.default_repository_class']);
228
229 2
            $config->setNamingStrategy($container['orm.strategy.naming']);
230
            $config->setQuoteStrategy($container['orm.strategy.quote']);
231 2
232 2
            $config->setEntityListenerResolver($container['orm.entity_listener_resolver']);
233 2
            $config->setRepositoryFactory($container['orm.repository_factory']);
234 2
235
            $config->setSecondLevelCacheEnabled($container['orm.second_level_cache.enabled']);
236 2
            $config->setSecondLevelCacheConfiguration($container['orm.second_level_cache.configuration']);
237
238
            $config->setDefaultQueryHints($container['orm.default.query_hints']);
239
240
            return $config;
241
        };
242
    }
243
244 2
    /**
245 2
     * @param Container $container
246 2
     *
247 2
     * @return \Closure
248
     */
249 2
    private function getOrmMappingDriverChainDefinition(Container $container): \Closure
250 2
    {
251
        return $container->protect(function (string $name, Configuration $config, array $mappings) use ($container) {
252 2
            $container['orm.ems.options.initializer']();
253 2
254
            if (null === $name) {
255 2
                $name = $container['orm.ems.default'];
256 2
            }
257
258 2
            $cacheInstanceKey = 'orm.mapping_driver_chain.instances.'.$name;
259 2
            if (isset($container[$cacheInstanceKey])) {
260
                return $container[$cacheInstanceKey];
261 2
            }
262
263 2
            /** @var MappingDriverChain $chain */
264 2
            $chain = $container['orm.mapping_driver_chain.factory']();
265
            foreach ($mappings as $entity) {
266
                if (!is_array($entity)) {
267
                    throw new \InvalidArgumentException(
268
                        "The 'orm.em.options' option 'mappings' should be an array of arrays."
269
                    );
270
                }
271
272
                if (isset($entity['alias'])) {
273
                    $config->addEntityNamespace($entity['alias'], $entity['namespace']);
274 2
                }
275 2
276
                $factoryKey = sprintf('orm.mapping_driver.factory.%s', $entity['type']);
277 2
                if (!isset($container[$factoryKey])) {
278
                    throw new \InvalidArgumentException(
279
                        sprintf('There is no driver factory for type "%s"', $entity['type'])
280
                    );
281 2
                }
282 2
283
                $chain->addDriver($container[$factoryKey]($entity, $config), $entity['namespace']);
284
            }
285
286 2
            return $container[$cacheInstanceKey] = $chain;
287 2
        });
288
    }
289
290
    /**
291
     * @param Container $container
292
     *
293
     * @return \Closure
294
     */
295
    private function getOrmMappingDriverChainFactoryDefinition(Container $container): \Closure
296
    {
297 2
        return $container->protect(function () use ($container) {
298 2
            return new MappingDriverChain();
299 2
        });
300
    }
301
302
    /**
303
     * @param Container $container
304
     *
305
     * @return \Closure
306
     */
307
    private function getOrmMappingDriverFactoryAnnotation(Container $container): \Closure
308
    {
309 2
        return $container->protect(function (array $entity, Configuration $config) {
310 1
            $useSimpleAnnotationReader = $entity['use_simple_annotation_reader'] ?? true;
311
312 1
            return $config->newDefaultAnnotationDriver(
313 1
                (array) $entity['path'],
314 1
                $useSimpleAnnotationReader
315
            );
316 2
        });
317
    }
318
319
    /**
320
     * @param Container $container
321
     *
322
     * @return \Closure
323
     */
324
    private function getOrmMappingDriverFactoryYaml(Container $container): \Closure
325
    {
326 2
        return $container->protect(function (array $entity, Configuration $config) {
0 ignored issues
show
Unused Code introduced by
The parameter $config is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
327 1
            return new YamlDriver($entity['path']);
328 2
        });
329
    }
330
331
    /**
332
     * @param Container $container
333
     *
334
     * @return \Closure
335
     */
336
    private function getOrmMappingDriverFactorySimpleYaml(Container $container): \Closure
337
    {
338 2
        return $container->protect(function (array $entity, Configuration $config) {
0 ignored issues
show
Unused Code introduced by
The parameter $config is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
339 1
            return new SimplifiedYamlDriver([$entity['path'] => $entity['namespace']]);
340 2
        });
341
    }
342
343
    /**
344
     * @param Container $container
345
     *
346
     * @return \Closure
347
     */
348
    private function getOrmMappingDriverFactoryXml(Container $container): \Closure
349
    {
350 2
        return $container->protect(function (array $entity, Configuration $config) {
0 ignored issues
show
Unused Code introduced by
The parameter $config is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
351 1
            return new XmlDriver($entity['path']);
352 2
        });
353
    }
354
355
    /**
356
     * @param Container $container
357
     *
358
     * @return \Closure
359
     */
360
    private function getOrmMappingDriverFactorySimpleXml(Container $container): \Closure
361
    {
362 2
        return $container->protect(function (array $entity, Configuration $config) {
0 ignored issues
show
Unused Code introduced by
The parameter $config is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
363 1
            return new SimplifiedXmlDriver([$entity['path'] => $entity['namespace']]);
364 2
        });
365
    }
366
367
    /**
368
     * @param Container $container
369
     *
370
     * @return \Closure
371
     */
372
    private function getOrmMappingDriverFactoryPhp(Container $container): \Closure
373
    {
374 2
        return $container->protect(function (array $entity, Configuration $config) {
0 ignored issues
show
Unused Code introduced by
The parameter $config is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
375 1
            return new StaticPHPDriver($entity['path']);
376 2
        });
377
    }
378
379
    /**
380
     * @param Container $container
381
     *
382
     * @return \Closure
383
     */
384
    private function getOrmCacheLocatorDefinition(Container $container): \Closure
385
    {
386 2
        return $container->protect(function (string $name, string $cacheName, array $options) use ($container) {
387 2
            $cacheNameKey = $cacheName.'_cache';
388
389 2
            if (!isset($options[$cacheNameKey])) {
390 2
                $options[$cacheNameKey] = $container['orm.default_cache'];
391
            }
392
393 2
            if (isset($options[$cacheNameKey]) && !is_array($options[$cacheNameKey])) {
394
                $options[$cacheNameKey] = [
395
                    'driver' => $options[$cacheNameKey],
396
                ];
397
            }
398
399 2
            if (!isset($options[$cacheNameKey]['driver'])) {
400
                throw new \RuntimeException("No driver specified for '$cacheName'");
401
            }
402
403 2
            $driver = $options[$cacheNameKey]['driver'];
404
405 2
            $cacheInstanceKey = 'orm.cache.instances.'.$name.'.'.$cacheName;
406 2
            if (isset($container[$cacheInstanceKey])) {
407
                return $container[$cacheInstanceKey];
408
            }
409
410 2
            $cache = $container['orm.cache.factory']($driver, $options[$cacheNameKey]);
411
412 2
            if (isset($options['cache_namespace']) && $cache instanceof CacheProvider) {
413
                $cache->setNamespace($options['cache_namespace']);
414
            }
415
416 2
            return $container[$cacheInstanceKey] = $cache;
417 2
        });
418
    }
419
420
    /**
421
     * @param Container $container
422
     *
423
     * @return \Closure
424
     */
425
    private function getOrmCacheFactoryDefinition(Container $container): \Closure
426
    {
427 2
        return $container->protect(function (string $driver, array $cacheOptions) use ($container) {
428 2
            $cacheFactoryKey = 'orm.cache.factory.'.$driver;
429 2
            if (!isset($container[$cacheFactoryKey])) {
430
                throw new \RuntimeException(
431
                    sprintf('Factory "%s" for cache type "%s" not defined', $cacheFactoryKey, $driver)
432
                );
433
            }
434
435 2
            return $container[$cacheFactoryKey]($cacheOptions);
436 2
        });
437
    }
438
439
    /**
440
     * @param Container $container
441
     *
442
     * @return \Closure
443
     */
444
    private function getOrmCacheFactoryApcuDefinition(Container $container): \Closure
445
    {
446 2
        return $container->protect(function (array $cacheOptions) use ($container) {
0 ignored issues
show
Unused Code introduced by
The parameter $cacheOptions is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
447
            return new ApcuCache();
448 2
        });
449
    }
450
451
    /**
452
     * @param Container $container
453
     *
454
     * @return \Closure
455
     */
456
    private function getOrmCacheFactoryArrayDefinition(Container $container): \Closure
457
    {
458 2
        return $container->protect(function (array $cacheOptions) use ($container) {
0 ignored issues
show
Unused Code introduced by
The parameter $cacheOptions is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
459 2
            return new ArrayCache();
460 2
        });
461
    }
462
463
    /**
464
     * @param Container $container
465
     *
466
     * @return \Closure
467
     */
468
    private function getOrmCacheFactoryFilesystemDefinition(Container $container): \Closure
469
    {
470 2
        return $container->protect(function (array $cacheOptions) {
471
            if (empty($cacheOptions['path'])) {
472
                throw new \RuntimeException('FilesystemCache path not defined');
473
            }
474
475
            $cacheOptions += [
476
                'extension' => FilesystemCache::EXTENSION,
477
                'umask' => 0002,
478
            ];
479
480
            return new FilesystemCache($cacheOptions['path'], $cacheOptions['extension'], $cacheOptions['umask']);
481 2
        });
482
    }
483
484
    /**
485
     * @param Container $container
486
     *
487
     * @return \Closure
488
     */
489
    private function getOrmCacheFactoryMemcacheDefinition(Container $container): \Closure
490
    {
491 2
        return $container->protect(function (array $cacheOptions) use ($container) {
492
            if (empty($cacheOptions['host']) || empty($cacheOptions['port'])) {
493
                throw new \RuntimeException('Host and port options need to be specified for memcache cache');
494
            }
495
496
            $memcache = new \Memcache();
497
            $memcache->connect($cacheOptions['host'], $cacheOptions['port']);
498
499
            $cache = new MemcacheCache();
500
            $cache->setMemcache($memcache);
501
502
            return $cache;
503 2
        });
504
    }
505
506
    /**
507
     * @param Container $container
508
     *
509
     * @return \Closure
510
     */
511
    private function getOrmCacheFactoryMemcachedDefinition(Container $container): \Closure
512
    {
513 2
        return $container->protect(function (array $cacheOptions) use ($container) {
514
            if (empty($cacheOptions['host']) || empty($cacheOptions['port'])) {
515
                throw new \RuntimeException('Host and port options need to be specified for memcached cache');
516
            }
517
518
            $memcached = new \Memcached();
519
            $memcached->addServer($cacheOptions['host'], $cacheOptions['port']);
520
521
            $cache = new MemcachedCache();
522
            $cache->setMemcached($memcached);
523
524
            return $cache;
525 2
        });
526
    }
527
528
    /**
529
     * @param Container $container
530
     *
531
     * @return \Closure
532
     */
533
    private function getOrmCacheFactoryRedisDefinition(Container $container): \Closure
534
    {
535 2
        return $container->protect(function (array $cacheOptions) use ($container) {
536
            if (empty($cacheOptions['host']) || empty($cacheOptions['port'])) {
537
                throw new \RuntimeException('Host and port options need to be specified for redis cache');
538
            }
539
540
            $redis = new \Redis();
541
            $redis->connect($cacheOptions['host'], $cacheOptions['port']);
542
543
            if (isset($cacheOptions['password'])) {
544
                $redis->auth($cacheOptions['password']);
545
            }
546
547
            $cache = new RedisCache();
548
            $cache->setRedis($redis);
549
550
            return $cache;
551 2
        });
552
    }
553
554
    /**
555
     * @param Container $container
556
     *
557
     * @return \Closure
558
     */
559
    private function getOrmCacheFactoryXCacheDefinition(Container $container): \Closure
560
    {
561 2
        return $container->protect(function (array $cacheOptions) use ($container) {
0 ignored issues
show
Unused Code introduced by
The parameter $cacheOptions is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
562
            return new XcacheCache();
563 2
        });
564
    }
565
566
    /**
567
     * @param Container $container
568
     *
569
     * @return \Closure
570
     */
571
    private function getOrmNamingStrategyDefinition(Container $container): \Closure
572
    {
573 2
        return function () use ($container) {
574 2
            return new DefaultNamingStrategy();
575 2
        };
576
    }
577
578
    /**
579
     * @param Container $container
580
     *
581
     * @return \Closure
582
     */
583
    private function getOrmQuoteStrategyDefinition(Container $container): \Closure
584
    {
585 2
        return function () use ($container) {
586 2
            return new DefaultQuoteStrategy();
587 2
        };
588
    }
589
590
    /**
591
     * @param Container $container
592
     *
593
     * @return \Closure
594
     */
595
    private function getOrmEntityListenerResolverDefinition(Container $container): \Closure
596
    {
597 2
        return function () use ($container) {
598 2
            return new DefaultEntityListenerResolver();
599 2
        };
600
    }
601
602
    /**
603
     * @param Container $container
604
     *
605
     * @return \Closure
606
     */
607
    private function getOrmRepositoryFactoryDefinition(Container $container): \Closure
608
    {
609 2
        return function () use ($container) {
610 2
            return new DefaultRepositoryFactory();
611 2
        };
612
    }
613
614
    /**
615
     * @param Container $container
616
     *
617
     * @return \Closure
618
     */
619
    private function getOrmSecondLevelCacheConfigurationDefinition(Container $container): \Closure
620
    {
621 2
        return function () use ($container) {
622 2
            return new CacheConfiguration();
623 2
        };
624
    }
625
626
    /**
627
     * @param Container $container
628
     *
629
     * @return \Closure
630
     */
631
    private function getOrmEmDefinition(Container $container): \Closure
632
    {
633 2
        return function () use ($container) {
634 2
            $ems = $container['orm.ems'];
635
636 2
            return $ems[$container['orm.ems.default']];
637 2
        };
638
    }
639
640
    /**
641
     * @param Container $container
642
     *
643
     * @return \Closure
644
     */
645
    private function getOrmEmConfigDefinition(Container $container): \Closure
646
    {
647 2
        return function () use ($container) {
648 2
            $configs = $container['orm.ems.config'];
649
650 2
            return $configs[$container['orm.ems.default']];
651 2
        };
652
    }
653
}
654