|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Application\Doctrine\ORM; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Persistence\ManagerRegistry; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @author Borut Balažek <[email protected]> |
|
9
|
|
|
*/ |
|
10
|
|
|
class DoctrineManagerRegistry |
|
|
|
|
|
|
11
|
|
|
implements ManagerRegistry |
|
|
|
|
|
|
12
|
|
|
{ |
|
13
|
|
|
protected $managers; |
|
14
|
|
|
protected $connections; |
|
15
|
|
|
protected $defaultManager; |
|
16
|
|
|
protected $defaultConnection; |
|
17
|
|
|
protected $name; |
|
18
|
|
|
|
|
19
|
|
|
public function __construct($name, array $connections, array $managers, $defaultConnection = 'default', $defaultManager = 'default') |
|
20
|
|
|
{ |
|
21
|
|
|
$this->name = $name; |
|
22
|
|
|
$this->managers = $managers; |
|
23
|
|
|
$this->connections = $connections; |
|
24
|
|
|
$this->defaultManager = $defaultManager; |
|
25
|
|
|
$this->defaultConnection = $defaultConnection; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* {@inheritDoc} |
|
30
|
|
|
*/ |
|
31
|
|
|
public function getDefaultConnectionName() |
|
32
|
|
|
{ |
|
33
|
|
|
return $this->defaultConnection; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* {@inheritDoc} |
|
38
|
|
|
*/ |
|
39
|
|
|
public function getConnection($name = null) |
|
40
|
|
|
{ |
|
41
|
|
|
if ($name === null) { |
|
42
|
|
|
$name = $this->getDefaultConnectionName(); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
return $this->connections[$name]; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* {@inheritDoc} |
|
50
|
|
|
*/ |
|
51
|
|
|
public function getConnections() |
|
52
|
|
|
{ |
|
53
|
|
|
return $this->connections; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* {@inheritDoc} |
|
58
|
|
|
*/ |
|
59
|
|
|
public function getConnectionNames() |
|
60
|
|
|
{ |
|
61
|
|
|
array_keys($this->connections); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* {@inheritDoc} |
|
66
|
|
|
*/ |
|
67
|
|
|
public function getDefaultManagerName() |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->defaultManager; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* {@inheritDoc} |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getManager($name = null) |
|
76
|
|
|
{ |
|
77
|
|
|
if ($name === null) { |
|
78
|
|
|
$name = $this->getDefaultManagerName(); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
return $this->managers[$name]; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* {@inheritDoc} |
|
86
|
|
|
*/ |
|
87
|
|
|
public function getManagers() |
|
88
|
|
|
{ |
|
89
|
|
|
return $this->managers; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* {@inheritDoc} |
|
94
|
|
|
*/ |
|
95
|
|
|
public function getManagerNames() |
|
96
|
|
|
{ |
|
97
|
|
|
return array_keys($this->managers); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* {@inheritDoc} |
|
102
|
|
|
*/ |
|
103
|
|
|
public function getRepository($persistentObject, $persistentManagerName = null) |
|
104
|
|
|
{ |
|
105
|
|
|
$this->getManager($persistentManagerName)->getRepository($persistentObject); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* {@inheritDoc} |
|
110
|
|
|
*/ |
|
111
|
|
|
public function getManagerForClass($class) |
|
112
|
|
|
{ |
|
113
|
|
|
foreach ($this->managers as $manager) { |
|
114
|
|
|
/* @var $manager \Doctrine\ORM\EntityManager */ |
|
115
|
|
|
if (!$manager->getMetadataFactory()->isTransient($class)) { |
|
116
|
|
|
return $manager; |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
return; |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|