1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/nnx-framework/doctrine-fixture-module |
4
|
|
|
* @author Malofeykin Andrey <[email protected]> |
5
|
|
|
*/ |
6
|
|
|
namespace Nnx\DoctrineFixtureModule\Utils; |
7
|
|
|
|
8
|
|
|
use Zend\EventManager\EventManagerAwareTrait; |
9
|
|
|
use Doctrine\Common\Persistence\ManagerRegistry; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class ManagerRegistryProvider |
13
|
|
|
* |
14
|
|
|
* @package Nnx\DoctrineFixtureModule\Utils |
15
|
|
|
*/ |
16
|
|
|
class ManagerRegistryProvider implements ManagerRegistryProviderInterface |
17
|
|
|
{ |
18
|
|
|
use EventManagerAwareTrait; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Компонент для работы с ObjectManager's |
22
|
|
|
* |
23
|
|
|
* @var ManagerRegistry |
24
|
|
|
*/ |
25
|
|
|
protected $managerRegistry; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Идендификатор EventManager'a |
29
|
|
|
* |
30
|
|
|
* @var array |
31
|
|
|
*/ |
32
|
|
|
protected $eventIdentifier = [ |
33
|
|
|
'DoctrineManagerRegistry' |
34
|
|
|
]; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Возвращает компонент для работы с ObjectManager's |
38
|
|
|
* |
39
|
|
|
* @return ManagerRegistry |
40
|
|
|
* |
41
|
|
|
* @throws Exception\RuntimeException |
42
|
|
|
*/ |
43
|
|
|
public function getManagerRegistry() |
44
|
|
|
{ |
45
|
|
|
if (null !== $this->managerRegistry) { |
46
|
|
|
return $this->managerRegistry; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
//@see \Nnx\Doctrine\Listener\ManagerRegistryListener |
50
|
|
|
$results = $this->getEventManager()->trigger('get.doctrineManagerRegistry', $this, [], function ($managerRegistry) { |
51
|
|
|
return $managerRegistry instanceof ManagerRegistry; |
52
|
|
|
}); |
53
|
|
|
|
54
|
|
|
$managerRegistry = $results->last(); |
55
|
|
|
|
56
|
|
|
if (!$managerRegistry instanceof ManagerRegistry) { |
57
|
|
|
$errMsg = 'ManagerRegistry not found'; |
58
|
|
|
throw new Exception\RuntimeException($errMsg); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$this->managerRegistry = $managerRegistry; |
62
|
|
|
return $managerRegistry; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Устанавливает компонент для работы с ObjectManager's |
67
|
|
|
* |
68
|
|
|
* @param ManagerRegistry $managerRegistry |
69
|
|
|
* |
70
|
|
|
* @return $this |
71
|
|
|
*/ |
72
|
|
|
public function setManagerRegistry(ManagerRegistry $managerRegistry) |
73
|
|
|
{ |
74
|
|
|
$this->managerRegistry = $managerRegistry; |
75
|
|
|
|
76
|
|
|
return $this; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|