|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Arp\LaminasDoctrine\Factory\Service\EntityManager; |
|
6
|
|
|
|
|
7
|
|
|
use Arp\LaminasDoctrine\Config\EntityManagerConfigs; |
|
8
|
|
|
use Arp\LaminasDoctrine\Service\EntityManager\EntityManagerContainer; |
|
9
|
|
|
use Arp\LaminasDoctrine\Service\EntityManager\EntityManagerProvider; |
|
10
|
|
|
use Arp\LaminasDoctrine\Service\EntityManager\EntityManagerProviderInterface; |
|
11
|
|
|
use Arp\LaminasDoctrine\Service\EntityManager\Exception\EntityManagerProviderException; |
|
12
|
|
|
use Arp\LaminasFactory\AbstractFactory; |
|
13
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
14
|
|
|
use Laminas\ServiceManager\Exception\ServiceNotCreatedException; |
|
15
|
|
|
use Laminas\ServiceManager\Exception\ServiceNotFoundException; |
|
16
|
|
|
use Psr\Container\ContainerExceptionInterface; |
|
17
|
|
|
use Psr\Container\ContainerInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @author Alex Patterson <[email protected]> |
|
21
|
|
|
* @package Arp\LaminasDoctrine\Factory\Service |
|
22
|
|
|
*/ |
|
23
|
|
|
final class EntityManagerProviderFactory extends AbstractFactory |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @param ContainerInterface $container |
|
27
|
|
|
* @param string $requestedName |
|
28
|
|
|
* @param array<mixed>|null $options |
|
29
|
|
|
* |
|
30
|
|
|
* @return EntityManagerProviderInterface |
|
31
|
|
|
* |
|
32
|
|
|
* @throws ServiceNotCreatedException |
|
33
|
|
|
* @throws ServiceNotFoundException |
|
34
|
|
|
* @throws ContainerExceptionInterface |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __invoke( |
|
37
|
|
|
ContainerInterface $container, |
|
38
|
|
|
string $requestedName, |
|
39
|
|
|
array $options = null |
|
40
|
|
|
): EntityManagerProviderInterface { |
|
41
|
|
|
/** @var EntityManagerConfigs $configs */ |
|
42
|
|
|
$configs = $this->getService($container, EntityManagerConfigs::class, $requestedName); |
|
43
|
|
|
|
|
44
|
|
|
/** @var EntityManagerContainer $entityManagerManager */ |
|
45
|
|
|
$entityManagerManager = $this->getService($container, EntityManagerContainer::class, $requestedName); |
|
46
|
|
|
|
|
47
|
|
|
/** @var EntityManagerInterface[] $entityManagers */ |
|
48
|
|
|
$entityManagers = []; |
|
49
|
|
|
|
|
50
|
|
|
try { |
|
51
|
|
|
return new EntityManagerProvider($configs, $entityManagerManager, $entityManagers); |
|
52
|
|
|
} catch (EntityManagerProviderException $e) { |
|
53
|
|
|
throw new ServiceNotCreatedException( |
|
54
|
|
|
sprintf('Failed to create entity manager provider \'%s\': %s', $requestedName, $e->getMessage()), |
|
55
|
|
|
$e->getCode(), |
|
56
|
|
|
$e |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|