|
@@ 191-217 (lines=27) @@
|
| 188 |
|
* @return ObjectManager |
| 189 |
|
* @throws \Nnx\Doctrine\ManagerRegistry\Exception\ObjectManagerNotFoundException |
| 190 |
|
*/ |
| 191 |
|
protected function getObjectManagerByName($name) |
| 192 |
|
{ |
| 193 |
|
if (array_key_exists($name, $this->objectManagerByName)) { |
| 194 |
|
return $this->objectManagerByName[$name]; |
| 195 |
|
} |
| 196 |
|
|
| 197 |
|
$event = clone $this->getManagerRegistryResourceEventPrototype(); |
| 198 |
|
$event->setName(ManagerRegistryResourceEvent::RESOLVE_OBJECT_MANAGER_EVENT); |
| 199 |
|
$event->setResourceName($name); |
| 200 |
|
$event->setTarget($this); |
| 201 |
|
|
| 202 |
|
|
| 203 |
|
$resultsEvent = $this->getEventManager()->trigger($event, function ($objectManager) { |
| 204 |
|
return $objectManager instanceof ObjectManager; |
| 205 |
|
}); |
| 206 |
|
|
| 207 |
|
$objectManager = $resultsEvent->last(); |
| 208 |
|
|
| 209 |
|
if (!$objectManager instanceof ObjectManager) { |
| 210 |
|
$errMsg = sprintf('Object manager %s not found', $name); |
| 211 |
|
throw new Exception\ObjectManagerNotFoundException($errMsg); |
| 212 |
|
} |
| 213 |
|
|
| 214 |
|
$this->objectManagerByName[$name] = $objectManager; |
| 215 |
|
|
| 216 |
|
return $this->objectManagerByName[$name]; |
| 217 |
|
} |
| 218 |
|
|
| 219 |
|
|
| 220 |
|
/** |
|
@@ 228-254 (lines=27) @@
|
| 225 |
|
* @return mixed |
| 226 |
|
* @throws \Nnx\Doctrine\ManagerRegistry\Exception\ConnectionNotFoundException |
| 227 |
|
*/ |
| 228 |
|
protected function getConnectionByName($name) |
| 229 |
|
{ |
| 230 |
|
if (array_key_exists($name, $this->connectionByName)) { |
| 231 |
|
return $this->connectionByName[$name]; |
| 232 |
|
} |
| 233 |
|
|
| 234 |
|
$event = clone $this->getManagerRegistryResourceEventPrototype(); |
| 235 |
|
$event->setName(ManagerRegistryResourceEvent::RESOLVE_CONNECTION_EVENT); |
| 236 |
|
$event->setResourceName($name); |
| 237 |
|
$event->setTarget($this); |
| 238 |
|
|
| 239 |
|
|
| 240 |
|
$resultsEvent = $this->getEventManager()->trigger($event, function ($connection) { |
| 241 |
|
return is_object($connection); |
| 242 |
|
}); |
| 243 |
|
|
| 244 |
|
$connection = $resultsEvent->last(); |
| 245 |
|
|
| 246 |
|
if (!is_object($connection)) { |
| 247 |
|
$errMsg = sprintf('Connection %s not found', $name); |
| 248 |
|
throw new Exception\ConnectionNotFoundException($errMsg); |
| 249 |
|
} |
| 250 |
|
|
| 251 |
|
$this->connectionByName[$name] = $connection; |
| 252 |
|
|
| 253 |
|
return $this->connectionByName[$name]; |
| 254 |
|
} |
| 255 |
|
|
| 256 |
|
|
| 257 |
|
/** |