1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Vox\Webservice; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Persistence\ManagerRegistry; |
6
|
|
|
use Doctrine\Common\Persistence\ObjectRepository; |
7
|
|
|
|
8
|
|
|
class TransferManagerRegistry implements ManagerRegistry |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var TransferManagerInterface[] |
12
|
|
|
*/ |
13
|
|
|
private $managers; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var WebserviceClientInterface[] |
17
|
|
|
*/ |
18
|
|
|
private $clients; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
private $defaultConnection; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
private $defaultManager; |
29
|
|
|
|
30
|
1 |
|
public function setManager(string $name, TransferManagerInterface $transferManager) |
31
|
|
|
{ |
32
|
1 |
|
$this->managers[$name] = $transferManager; |
33
|
1 |
|
} |
34
|
|
|
|
35
|
1 |
|
public function setClient(string $name, WebserviceClientInterface $client) |
36
|
|
|
{ |
37
|
1 |
|
$this->clients[$name] = $client; |
38
|
1 |
|
} |
39
|
|
|
|
40
|
1 |
|
public function setDefaultConnection(string $defaultConnection) |
41
|
|
|
{ |
42
|
1 |
|
$this->defaultConnection = $defaultConnection; |
43
|
1 |
|
} |
44
|
|
|
|
45
|
1 |
|
public function setDefaultManager(string $defaultManager) |
46
|
|
|
{ |
47
|
1 |
|
$this->defaultManager = $defaultManager; |
48
|
1 |
|
} |
49
|
|
|
|
50
|
|
|
public function getAliasNamespace($alias): string |
51
|
|
|
{ |
52
|
|
|
|
53
|
|
|
} |
|
|
|
|
54
|
|
|
|
55
|
1 |
|
public function getConnection($name = null): WebserviceClientInterface |
56
|
|
|
{ |
57
|
1 |
|
if (null === $name) { |
58
|
1 |
|
return isset($this->defaultConnection) ? $this->clients[$this->defaultConnection] : reset($this->clients); |
59
|
|
|
} |
60
|
|
|
|
61
|
1 |
|
return $this->clients[$name]; |
62
|
|
|
} |
63
|
|
|
|
64
|
1 |
|
public function getConnectionNames(): array |
65
|
|
|
{ |
66
|
1 |
|
return array_keys($this->clients); |
67
|
|
|
} |
68
|
|
|
|
69
|
1 |
|
public function getConnections(): array |
70
|
|
|
{ |
71
|
1 |
|
return $this->clients; |
72
|
|
|
} |
73
|
|
|
|
74
|
1 |
|
public function getDefaultConnectionName(): string |
75
|
|
|
{ |
76
|
1 |
|
return $this->defaultConnection ?? array_keys($this->clients)[0]; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function getDefaultManagerName(): string |
80
|
|
|
{ |
81
|
|
|
return $this->defaultManager ?? array_keys($this->managers)[0]; |
82
|
|
|
} |
83
|
|
|
|
84
|
1 |
|
public function getManager($name = null): TransferManagerInterface |
85
|
|
|
{ |
86
|
1 |
|
return $this->managers[$name ?? $this->getDefaultConnectionName()]; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function getManagerForClass($class) |
90
|
|
|
{ |
91
|
|
|
return $this->getManager(); |
92
|
|
|
} |
93
|
|
|
|
94
|
1 |
|
public function getManagerNames(): array |
95
|
|
|
{ |
96
|
1 |
|
return array_keys($this->managers); |
97
|
|
|
} |
98
|
|
|
|
99
|
1 |
|
public function getManagers(): array |
100
|
|
|
{ |
101
|
1 |
|
return $this->managers; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function getRepository($persistentObject, $persistentManagerName = null): ObjectRepository |
105
|
|
|
{ |
106
|
|
|
return $this->getManager($persistentManagerName)->getRepository($persistentObject); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function resetManager($name = null): TransferManagerInterface |
110
|
|
|
{ |
111
|
|
|
$manager = $this->getManager($name); |
112
|
|
|
$manager->clear(); |
113
|
|
|
|
114
|
|
|
return $manager; |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: