ManagerRegistryListener::getManagerRegistry()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * @link    https://github.com/nnx-framework/doctrine
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace Nnx\Doctrine\Listener;
7
8
use Zend\EventManager\AbstractListenerAggregate;
9
use Zend\EventManager\EventManagerInterface;
10
use Nnx\Doctrine\ManagerRegistry\ManagerRegistry;
11
12
/**
13
 * Class ResolverManagerRegistryResourceListener
14
 *
15
 * @package Nnx\Doctrine\Listener
16
 */
17
class ManagerRegistryListener extends AbstractListenerAggregate
18
{
19
20
    /**
21
     * ManagerRegistry
22
     *
23
     * @var ManagerRegistry
24
     */
25
    protected $managerRegistry;
26
27
    /**
28
     * ResolverManagerRegistryResourceListener constructor.
29
     *
30
     * @param ManagerRegistry $managerRegistry
31
     */
32
    public function __construct(ManagerRegistry $managerRegistry)
33
    {
34
        $this->setManagerRegistry($managerRegistry);
35
    }
36
37
    /**
38
     * @param EventManagerInterface $events
39
     *
40
     * @return mixed
41
     */
42
    public function attach(EventManagerInterface $events)
43
    {
44
        $sharedManager = $events->getSharedManager();
45
        $sharedManager->attach('DoctrineManagerRegistry', 'get.doctrineManagerRegistry', [$this, 'getDoctrineManagerRegistryHandler']);
46
    }
47
48
    /**
49
     * Обработчик события возникающего когда происходит попытка получить экземпляр ManagerRegistry
50
     *
51
     * @return ManagerRegistry
52
     */
53
    public function getDoctrineManagerRegistryHandler()
54
    {
55
        return $this->getManagerRegistry();
56
    }
57
58
59
60
    /**
61
     * Возвращает ManagerRegistry
62
     *
63
     * @return ManagerRegistry
64
     */
65
    public function getManagerRegistry()
66
    {
67
        return $this->managerRegistry;
68
    }
69
70
    /**
71
     * Устанавливает ManagerRegistry
72
     *
73
     * @param ManagerRegistry $managerRegistry
74
     *
75
     * @return $this
76
     */
77
    public function setManagerRegistry(ManagerRegistry $managerRegistry)
78
    {
79
        $this->managerRegistry = $managerRegistry;
80
81
        return $this;
82
    }
83
}
84