ManagerRegistryFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 4
dl 0
loc 36
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A createService() 0 16 2
1
<?php
2
/**
3
 * @link    https://github.com/nnx-framework/jms-serializer-module
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace Nnx\JmsSerializerModule\Util;
7
8
use Zend\EventManager\EventManagerAwareTrait;
9
use Zend\ServiceManager\FactoryInterface;
10
use Zend\ServiceManager\ServiceLocatorInterface;
11
use Doctrine\Common\Persistence\ManagerRegistry;
12
13
/**
14
 * Class ManagerRegistryFactory
15
 *
16
 * @package Nnx\JmsSerializerModule\Util
17
 */
18
class ManagerRegistryFactory implements FactoryInterface
19
{
20
    use EventManagerAwareTrait;
21
22
    /**
23
     * Идендификатор EventManager'a
24
     *
25
     * @var array
26
     */
27
    protected $eventIdentifier = [
28
        'DoctrineManagerRegistry'
29
    ];
30
31
    /**
32
     * @param ServiceLocatorInterface $serviceLocator
33
     *
34
     * @return ManagerRegistry
35
     * @throws \Nnx\JmsSerializerModule\Util\Exception\RuntimeException
36
     */
37
    public function createService(ServiceLocatorInterface $serviceLocator)
38
    {
39
        //@see \Nnx\Doctrine\Listener\ManagerRegistryListener
40
        $results = $this->getEventManager()->trigger('get.doctrineManagerRegistry', $this, [], function ($managerRegistry) {
41
            return $managerRegistry instanceof ManagerRegistry;
42
        });
43
44
        $managerRegistry = $results->last();
45
46
        if (!$managerRegistry instanceof ManagerRegistry) {
47
            $errMsg = 'ManagerRegistry not found';
48
            throw new Exception\RuntimeException($errMsg);
49
        }
50
51
        return $managerRegistry;
52
    }
53
}
54