Passed
Push — master ( ecdbe9...d4cbca )
by Dominik
02:30
created

getOrmCacheFactoryMemcacheDefinition()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 7.2349

Importance

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