Passed
Push — master ( 58337e...ecdbe9 )
by Dominik
02:31 queued 10s
created

getOrmEmDefaultOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 2
cts 2
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
crap 1
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 3
    public function register(Container $container)
46
    {
47 3
        $container['orm.em.default_options'] = $this->getOrmEmDefaultOptions();
48 3
        $container['orm.ems.options.initializer'] = $this->getOrmEmsOptionsInitializerDefinition($container);
49 3
        $container['orm.ems'] = $this->getOrmEmsDefinition($container);
50 3
        $container['orm.ems.config'] = $this->getOrmEmsConfigServiceProvider($container);
51 3
        $container['orm.proxies_dir'] = sys_get_temp_dir();
52 3
        $container['orm.auto_generate_proxies'] = true;
53 3
        $container['orm.proxies_namespace'] = 'DoctrineProxy';
54 3
        $container['orm.mapping_driver_chain'] = $this->getOrmMappingDriverChainDefinition($container);
55 3
        $container['orm.mapping_driver_chain.factory'] = $this->getOrmMappingDriverChainFactoryDefinition($container);
56 3
        $container['orm.mapping_driver.factory.annotation'] = $this->getOrmMappingDriverFactoryAnnotation($container);
57 3
        $container['orm.mapping_driver.factory.yml'] = $this->getOrmMappingDriverFactoryYaml($container);
58 3
        $container['orm.mapping_driver.factory.simple_yml'] = $this->getOrmMappingDriverFactorySimpleYaml($container);
59 3
        $container['orm.mapping_driver.factory.xml'] = $this->getOrmMappingDriverFactoryXml($container);
60 3
        $container['orm.mapping_driver.factory.simple_xml'] = $this->getOrmMappingDriverFactorySimpleXml($container);
61 3
        $container['orm.mapping_driver.factory.php'] = $this->getOrmMappingDriverFactoryPhp($container);
62 3
        $container['orm.cache.locator'] = $this->getOrmCacheLocatorDefinition($container);
63 3
        $container['orm.cache.factory'] = $this->getOrmCacheFactoryDefinition($container);
64 3
        $container['orm.cache.factory.apcu'] = $this->getOrmCacheFactoryApcuDefinition($container);
65 3
        $container['orm.cache.factory.array'] = $this->getOrmCacheFactoryArrayDefinition($container);
66 3
        $container['orm.cache.factory.filesystem'] = $this->getOrmCacheFactoryFilesystemDefinition($container);
67 3
        $container['orm.cache.factory.memcache'] = $this->getOrmCacheFactoryMemcacheDefinition($container);
68 3
        $container['orm.cache.factory.memcached'] = $this->getOrmCacheFactoryMemcachedDefinition($container);
69 3
        $container['orm.cache.factory.redis'] = $this->getOrmCacheFactoryRedisDefinition($container);
70 3
        $container['orm.cache.factory.xcache'] = $this->getOrmCacheFactoryXCacheDefinition($container);
71 3
        $container['orm.default_cache'] = ['driver' => 'array'];
72 3
        $container['orm.custom.functions.string'] = [];
73 3
        $container['orm.custom.functions.numeric'] = [];
74 3
        $container['orm.custom.functions.datetime'] = [];
75 3
        $container['orm.custom.hydration_modes'] = [];
76 3
        $container['orm.class_metadata_factory_name'] = ClassMetadataFactory::class;
77 3
        $container['orm.default_repository_class'] = EntityRepository::class;
78 3
        $container['orm.strategy.naming'] = $this->getOrmNamingStrategyDefinition($container);
79 3
        $container['orm.strategy.quote'] = $this->getOrmQuoteStrategyDefinition($container);
80 3
        $container['orm.entity_listener_resolver'] = $this->getOrmEntityListenerResolverDefinition($container);
81 3
        $container['orm.repository_factory'] = $this->getOrmRepositoryFactoryDefinition($container);
82 3
        $container['orm.second_level_cache.enabled'] = false;
83 3
        $container['orm.second_level_cache.configuration'] = $this->getOrmSecondLevelCacheConfigurationDefinition($container);
84 3
        $container['orm.default.query_hints'] = [];
85 3
        $container['orm.em'] = $this->getOrmEmDefinition($container);
86 3
        $container['orm.em.config'] = $this->getOrmEmConfigDefinition($container);
87 3
    }
88
89
    /**
90
     * @return array
91
     */
92 3
    private function getOrmEmDefaultOptions(): array
93
    {
94
        return [
95 3
            '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 3
        return $container->protect(function () use ($container) {
109 3
            static $initialized = false;
110
111 3
            if ($initialized) {
112 3
                return;
113
            }
114
115 3
            $initialized = true;
116
117 3
            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 3
            $tmp = $container['orm.ems.options'];
124 3
            foreach ($tmp as $name => &$options) {
125 3
                $options = array_replace($container['orm.em.default_options'], $options);
126
127 3
                if (!isset($container['orm.ems.default'])) {
128 3
                    $container['orm.ems.default'] = $name;
129
                }
130
            }
131
132 3
            $container['orm.ems.options'] = $tmp;
133 3
        });
134
    }
135
136
    /**
137
     * @param Container $container
138
     *
139
     * @return \Closure
140
     */
141
    private function getOrmEmsDefinition(Container $container): \Closure
142
    {
143 3
        return function () use ($container) {
144 3
            $container['orm.ems.options.initializer']();
145
146 3
            $ems = new Container();
147 3
            foreach ($container['orm.ems.options'] as $name => $options) {
148 3
                if ($container['orm.ems.default'] === $name) {
149
                    // we use shortcuts here in case the default has been overridden
150 3
                    $config = $container['orm.em.config'];
151
                } else {
152 1
                    $config = $container['orm.ems.config'][$name];
153
                }
154
155 3
                $ems[$name] = function () use ($container, $options, $config) {
156 3
                    return EntityManager::create(
157 3
                        $container['dbs'][$options['connection']],
158 3
                        $config,
159 3
                        $container['dbs.event_manager'][$options['connection']]
160
                    );
161 3
                };
162
            }
163
164 3
            return $ems;
165 3
        };
166
    }
167
168
    /**
169
     * @param Container $container
170
     *
171
     * @return \Closure
172
     */
173
    private function getOrmEmsConfigServiceProvider(Container $container): \Closure
174
    {
175 3
        return function () use ($container) {
176 3
            $container['orm.ems.options.initializer']();
177
178 3
            $configs = new Container();
179 3
            foreach ($container['orm.ems.options'] as $name => $options) {
180 3
                $configs[$name] = $this->getOrmEmConfigByNameAndOptionsDefinition($container, $name, $options);
181
            }
182
183 3
            return $configs;
184 3
        };
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 3
        return function () use ($container, $name, $options) {
200 3
            $config = new Configuration();
201
202 3
            $config->setProxyDir($container['orm.proxies_dir']);
203 3
            $config->setAutoGenerateProxyClasses($container['orm.auto_generate_proxies']);
204 3
            $config->setProxyNamespace($container['orm.proxies_namespace']);
205 3
            $config->setMetadataDriverImpl(
206 3
                $container['orm.mapping_driver_chain']($name, $config, (array) $options['mappings'])
207
            );
208 3
            $config->setQueryCacheImpl($container['orm.cache.locator']($name, 'query', $options));
209 3
            $config->setHydrationCacheImpl($container['orm.cache.locator']($name, 'hydration', $options));
210 3
            $config->setMetadataCacheImpl($container['orm.cache.locator']($name, 'metadata', $options));
211 3
            $config->setResultCacheImpl($container['orm.cache.locator']($name, 'result', $options));
212
213 3
            foreach ((array) $options['types'] as $typeName => $typeClass) {
214
                if (Type::hasType($typeName)) {
215
                    Type::overrideType($typeName, $typeClass);
216
                } else {
217
                    Type::addType($typeName, $typeClass);
218
                }
219
            }
220
221 3
            $config->setCustomStringFunctions($container['orm.custom.functions.string']);
222 3
            $config->setCustomNumericFunctions($container['orm.custom.functions.numeric']);
223 3
            $config->setCustomDatetimeFunctions($container['orm.custom.functions.datetime']);
224 3
            $config->setCustomHydrationModes($container['orm.custom.hydration_modes']);
225
226 3
            $config->setClassMetadataFactoryName($container['orm.class_metadata_factory_name']);
227 3
            $config->setDefaultRepositoryClassName($container['orm.default_repository_class']);
228
229 3
            $config->setNamingStrategy($container['orm.strategy.naming']);
230 3
            $config->setQuoteStrategy($container['orm.strategy.quote']);
231
232 3
            $config->setEntityListenerResolver($container['orm.entity_listener_resolver']);
233 3
            $config->setRepositoryFactory($container['orm.repository_factory']);
234
235 3
            $config->setSecondLevelCacheEnabled($container['orm.second_level_cache.enabled']);
236 3
            $config->setSecondLevelCacheConfiguration($container['orm.second_level_cache.configuration']);
237
238 3
            $config->setDefaultQueryHints($container['orm.default.query_hints']);
239
240 3
            return $config;
241 3
        };
242
    }
243
244
    /**
245
     * @param Container $container
246
     *
247
     * @return \Closure
248
     */
249
    private function getOrmMappingDriverChainDefinition(Container $container): \Closure
250
    {
251 3
        return $container->protect(function (string $name, Configuration $config, array $mappings) use ($container) {
252 3
            $container['orm.ems.options.initializer']();
253
254 3
            $cacheInstanceKey = 'orm.mapping_driver_chain.instances.'.$name;
255 3
            if (isset($container[$cacheInstanceKey])) {
256
                return $container[$cacheInstanceKey];
257
            }
258
259
            /** @var MappingDriverChain $chain */
260 3
            $chain = $container['orm.mapping_driver_chain.factory']();
261 3
            foreach ($mappings as $entity) {
262 2
                if (!is_array($entity)) {
263
                    throw new \InvalidArgumentException(
264
                        "The 'orm.em.options' option 'mappings' should be an array of arrays."
265
                    );
266
                }
267
268 2
                if (isset($entity['alias'])) {
269
                    $config->addEntityNamespace($entity['alias'], $entity['namespace']);
270
                }
271
272 2
                $factoryKey = sprintf('orm.mapping_driver.factory.%s', $entity['type']);
273 2
                if (!isset($container[$factoryKey])) {
274
                    throw new \InvalidArgumentException(
275
                        sprintf('There is no driver factory for type "%s"', $entity['type'])
276
                    );
277
                }
278
279 2
                $chain->addDriver($container[$factoryKey]($entity, $config), $entity['namespace']);
280
            }
281
282 3
            return $container[$cacheInstanceKey] = $chain;
283 3
        });
284
    }
285
286
    /**
287
     * @param Container $container
288
     *
289
     * @return \Closure
290
     */
291
    private function getOrmMappingDriverChainFactoryDefinition(Container $container): \Closure
292
    {
293 3
        return $container->protect(function () use ($container) {
294 3
            return new MappingDriverChain();
295 3
        });
296
    }
297
298
    /**
299
     * @param Container $container
300
     *
301
     * @return \Closure
302
     */
303
    private function getOrmMappingDriverFactoryAnnotation(Container $container): \Closure
304
    {
305 3
        return $container->protect(function (array $entity, Configuration $config) {
306 2
            $useSimpleAnnotationReader = $entity['use_simple_annotation_reader'] ?? true;
307
308 2
            return $config->newDefaultAnnotationDriver(
309 2
                (array) $entity['path'],
310 2
                $useSimpleAnnotationReader
311
            );
312 3
        });
313
    }
314
315
    /**
316
     * @param Container $container
317
     *
318
     * @return \Closure
319
     */
320
    private function getOrmMappingDriverFactoryYaml(Container $container): \Closure
321
    {
322 3
        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...
323 2
            return new YamlDriver($entity['path']);
324 3
        });
325
    }
326
327
    /**
328
     * @param Container $container
329
     *
330
     * @return \Closure
331
     */
332
    private function getOrmMappingDriverFactorySimpleYaml(Container $container): \Closure
333
    {
334 3
        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...
335 2
            return new SimplifiedYamlDriver([$entity['path'] => $entity['namespace']]);
336 3
        });
337
    }
338
339
    /**
340
     * @param Container $container
341
     *
342
     * @return \Closure
343
     */
344
    private function getOrmMappingDriverFactoryXml(Container $container): \Closure
345
    {
346 3
        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...
347 2
            return new XmlDriver($entity['path']);
348 3
        });
349
    }
350
351
    /**
352
     * @param Container $container
353
     *
354
     * @return \Closure
355
     */
356
    private function getOrmMappingDriverFactorySimpleXml(Container $container): \Closure
357
    {
358 3
        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...
359 2
            return new SimplifiedXmlDriver([$entity['path'] => $entity['namespace']]);
360 3
        });
361
    }
362
363
    /**
364
     * @param Container $container
365
     *
366
     * @return \Closure
367
     */
368
    private function getOrmMappingDriverFactoryPhp(Container $container): \Closure
369
    {
370 3
        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...
371 2
            return new StaticPHPDriver($entity['path']);
372 3
        });
373
    }
374
375
    /**
376
     * @param Container $container
377
     *
378
     * @return \Closure
379
     */
380
    private function getOrmCacheLocatorDefinition(Container $container): \Closure
381
    {
382 3
        return $container->protect(function (string $name, string $cacheName, array $options) use ($container) {
383 3
            $cacheNameKey = $cacheName.'_cache';
384
385 3
            if (!isset($options[$cacheNameKey])) {
386 3
                $options[$cacheNameKey] = $container['orm.default_cache'];
387
            }
388
389 3
            if (isset($options[$cacheNameKey]) && !is_array($options[$cacheNameKey])) {
390
                $options[$cacheNameKey] = [
391
                    'driver' => $options[$cacheNameKey],
392
                ];
393
            }
394
395 3
            if (!isset($options[$cacheNameKey]['driver'])) {
396
                throw new \RuntimeException("No driver specified for '$cacheName'");
397
            }
398
399 3
            $driver = $options[$cacheNameKey]['driver'];
400
401 3
            $cacheInstanceKey = 'orm.cache.instances.'.$name.'.'.$cacheName;
402 3
            if (isset($container[$cacheInstanceKey])) {
403
                return $container[$cacheInstanceKey];
404
            }
405
406 3
            $cache = $container['orm.cache.factory']($driver, $options[$cacheNameKey]);
407
408 3
            if (isset($options['cache_namespace']) && $cache instanceof CacheProvider) {
409
                $cache->setNamespace($options['cache_namespace']);
410
            }
411
412 3
            return $container[$cacheInstanceKey] = $cache;
413 3
        });
414
    }
415
416
    /**
417
     * @param Container $container
418
     *
419
     * @return \Closure
420
     */
421
    private function getOrmCacheFactoryDefinition(Container $container): \Closure
422
    {
423 3
        return $container->protect(function (string $driver, array $cacheOptions) use ($container) {
424 3
            $cacheFactoryKey = 'orm.cache.factory.'.$driver;
425 3
            if (!isset($container[$cacheFactoryKey])) {
426
                throw new \RuntimeException(
427
                    sprintf('Factory "%s" for cache type "%s" not defined', $cacheFactoryKey, $driver)
428
                );
429
            }
430
431 3
            return $container[$cacheFactoryKey]($cacheOptions);
432 3
        });
433
    }
434
435
    /**
436
     * @param Container $container
437
     *
438
     * @return \Closure
439
     */
440
    private function getOrmCacheFactoryApcuDefinition(Container $container): \Closure
441
    {
442 3
        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...
443
            return new ApcuCache();
444 3
        });
445
    }
446
447
    /**
448
     * @param Container $container
449
     *
450
     * @return \Closure
451
     */
452
    private function getOrmCacheFactoryArrayDefinition(Container $container): \Closure
453
    {
454 3
        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...
455 3
            return new ArrayCache();
456 3
        });
457
    }
458
459
    /**
460
     * @param Container $container
461
     *
462
     * @return \Closure
463
     */
464
    private function getOrmCacheFactoryFilesystemDefinition(Container $container): \Closure
465
    {
466 3
        return $container->protect(function (array $cacheOptions) {
467
            if (empty($cacheOptions['path'])) {
468
                throw new \RuntimeException('FilesystemCache path not defined');
469
            }
470
471
            $cacheOptions += [
472
                'extension' => FilesystemCache::EXTENSION,
473
                'umask' => 0002,
474
            ];
475
476
            return new FilesystemCache($cacheOptions['path'], $cacheOptions['extension'], $cacheOptions['umask']);
477 3
        });
478
    }
479
480
    /**
481
     * @param Container $container
482
     *
483
     * @return \Closure
484
     */
485
    private function getOrmCacheFactoryMemcacheDefinition(Container $container): \Closure
486
    {
487 3
        return $container->protect(function (array $cacheOptions) use ($container) {
488
            if (empty($cacheOptions['host']) || empty($cacheOptions['port'])) {
489
                throw new \RuntimeException('Host and port options need to be specified for memcache cache');
490
            }
491
492
            $memcache = new \Memcache();
493
            $memcache->connect($cacheOptions['host'], $cacheOptions['port']);
494
495
            $cache = new MemcacheCache();
496
            $cache->setMemcache($memcache);
497
498
            return $cache;
499 3
        });
500
    }
501
502
    /**
503
     * @param Container $container
504
     *
505
     * @return \Closure
506
     */
507
    private function getOrmCacheFactoryMemcachedDefinition(Container $container): \Closure
508
    {
509 3
        return $container->protect(function (array $cacheOptions) use ($container) {
510
            if (empty($cacheOptions['host']) || empty($cacheOptions['port'])) {
511
                throw new \RuntimeException('Host and port options need to be specified for memcached cache');
512
            }
513
514
            $memcached = new \Memcached();
515
            $memcached->addServer($cacheOptions['host'], $cacheOptions['port']);
516
517
            $cache = new MemcachedCache();
518
            $cache->setMemcached($memcached);
519
520
            return $cache;
521 3
        });
522
    }
523
524
    /**
525
     * @param Container $container
526
     *
527
     * @return \Closure
528
     */
529
    private function getOrmCacheFactoryRedisDefinition(Container $container): \Closure
530
    {
531 3
        return $container->protect(function (array $cacheOptions) use ($container) {
532
            if (empty($cacheOptions['host']) || empty($cacheOptions['port'])) {
533
                throw new \RuntimeException('Host and port options need to be specified for redis cache');
534
            }
535
536
            $redis = new \Redis();
537
            $redis->connect($cacheOptions['host'], $cacheOptions['port']);
538
539
            if (isset($cacheOptions['password'])) {
540
                $redis->auth($cacheOptions['password']);
541
            }
542
543
            $cache = new RedisCache();
544
            $cache->setRedis($redis);
545
546
            return $cache;
547 3
        });
548
    }
549
550
    /**
551
     * @param Container $container
552
     *
553
     * @return \Closure
554
     */
555
    private function getOrmCacheFactoryXCacheDefinition(Container $container): \Closure
556
    {
557 3
        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...
558
            return new XcacheCache();
559 3
        });
560
    }
561
562
    /**
563
     * @param Container $container
564
     *
565
     * @return \Closure
566
     */
567
    private function getOrmNamingStrategyDefinition(Container $container): \Closure
568
    {
569 3
        return function () use ($container) {
570 3
            return new DefaultNamingStrategy();
571 3
        };
572
    }
573
574
    /**
575
     * @param Container $container
576
     *
577
     * @return \Closure
578
     */
579
    private function getOrmQuoteStrategyDefinition(Container $container): \Closure
580
    {
581 3
        return function () use ($container) {
582 3
            return new DefaultQuoteStrategy();
583 3
        };
584
    }
585
586
    /**
587
     * @param Container $container
588
     *
589
     * @return \Closure
590
     */
591
    private function getOrmEntityListenerResolverDefinition(Container $container): \Closure
592
    {
593 3
        return function () use ($container) {
594 3
            return new DefaultEntityListenerResolver();
595 3
        };
596
    }
597
598
    /**
599
     * @param Container $container
600
     *
601
     * @return \Closure
602
     */
603
    private function getOrmRepositoryFactoryDefinition(Container $container): \Closure
604
    {
605 3
        return function () use ($container) {
606 3
            return new DefaultRepositoryFactory();
607 3
        };
608
    }
609
610
    /**
611
     * @param Container $container
612
     *
613
     * @return \Closure
614
     */
615
    private function getOrmSecondLevelCacheConfigurationDefinition(Container $container): \Closure
616
    {
617 3
        return function () use ($container) {
618 3
            return new CacheConfiguration();
619 3
        };
620
    }
621
622
    /**
623
     * @param Container $container
624
     *
625
     * @return \Closure
626
     */
627
    private function getOrmEmDefinition(Container $container): \Closure
628
    {
629 3
        return function () use ($container) {
630 3
            $ems = $container['orm.ems'];
631
632 3
            return $ems[$container['orm.ems.default']];
633 3
        };
634
    }
635
636
    /**
637
     * @param Container $container
638
     *
639
     * @return \Closure
640
     */
641
    private function getOrmEmConfigDefinition(Container $container): \Closure
642
    {
643 3
        return function () use ($container) {
644 3
            $configs = $container['orm.ems.config'];
645
646 3
            return $configs[$container['orm.ems.default']];
647 3
        };
648
    }
649
}
650