|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @link https://github.com/nnx-framework/doctrine |
|
4
|
|
|
* @author Malofeykin Andrey <[email protected]> |
|
5
|
|
|
*/ |
|
6
|
|
|
namespace Nnx\Doctrine\ManagerRegistry; |
|
7
|
|
|
|
|
8
|
|
|
use Zend\EventManager\AbstractListenerAggregate; |
|
9
|
|
|
use Zend\EventManager\EventManagerInterface; |
|
10
|
|
|
use Nnx\Doctrine\Utils\DoctrineOrmModuleConfigInterface; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class ManagerRegistry |
|
14
|
|
|
* |
|
15
|
|
|
* @package Nnx\Doctrine\ManagerRegistry |
|
16
|
|
|
*/ |
|
17
|
|
|
class ParamsFromDoctrineModuleListener extends AbstractListenerAggregate |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Утилита для работы с конфигами DoctrineORMModule |
|
21
|
|
|
* |
|
22
|
|
|
* @var DoctrineOrmModuleConfigInterface |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $doctrineOrmModuleConfig; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* ParamsFromDoctrineModuleListener constructor. |
|
28
|
|
|
* |
|
29
|
|
|
* @param DoctrineOrmModuleConfigInterface $doctrineOrmModuleConfig |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct(DoctrineOrmModuleConfigInterface $doctrineOrmModuleConfig) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->setDoctrineOrmModuleConfig($doctrineOrmModuleConfig); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param EventManagerInterface $events |
|
38
|
|
|
* |
|
39
|
|
|
* @return mixed |
|
40
|
|
|
*/ |
|
41
|
|
|
public function attach(EventManagerInterface $events) |
|
42
|
|
|
{ |
|
43
|
|
|
$sharedManager = $events->getSharedManager(); |
|
44
|
|
|
$sharedManager->attach(ManagerRegistryFactory::class, ManagerRegistryFactory::EVENT_BUILD_LIST_CONNECTIONS, [$this, 'buildListConnectionsHandler']); |
|
45
|
|
|
$sharedManager->attach(ManagerRegistryFactory::class, ManagerRegistryFactory::EVENT_BUILD_LIST_OBJECT_MANAGERS, [$this, 'buildListObjectManagersHandler']); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Обработчик события бросаемого когда необходимо получить список доступных подключений |
|
50
|
|
|
* |
|
51
|
|
|
* @return array |
|
52
|
|
|
*/ |
|
53
|
|
|
public function buildListConnectionsHandler() |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->getDoctrineOrmModuleConfig()->getListConnectionName(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Обработчик события бросаемого когда необходимо получить список доступных ObjectManagers's |
|
61
|
|
|
* |
|
62
|
|
|
* @return array |
|
63
|
|
|
*/ |
|
64
|
|
|
public function buildListObjectManagersHandler() |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->getDoctrineOrmModuleConfig()->getListObjectManagerName(); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Возвращает утилиту для работы с конфигами DoctrineORMModule |
|
71
|
|
|
* |
|
72
|
|
|
* @return DoctrineOrmModuleConfigInterface |
|
73
|
|
|
*/ |
|
74
|
|
|
public function getDoctrineOrmModuleConfig() |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->doctrineOrmModuleConfig; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Устанавливает утилиту для работы с конфигами DoctrineORMModule |
|
81
|
|
|
* |
|
82
|
|
|
* @param DoctrineOrmModuleConfigInterface $doctrineOrmModuleConfig |
|
83
|
|
|
* |
|
84
|
|
|
* @return $this |
|
85
|
|
|
*/ |
|
86
|
|
|
public function setDoctrineOrmModuleConfig(DoctrineOrmModuleConfigInterface $doctrineOrmModuleConfig) |
|
87
|
|
|
{ |
|
88
|
|
|
$this->doctrineOrmModuleConfig = $doctrineOrmModuleConfig; |
|
89
|
|
|
|
|
90
|
|
|
return $this; |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|