|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Arp\LaminasDoctrine\Factory\Config; |
|
6
|
|
|
|
|
7
|
|
|
use Arp\LaminasDoctrine\Config\DoctrineConfig; |
|
8
|
|
|
use Arp\LaminasDoctrine\Config\ConfigurationConfigs; |
|
9
|
|
|
use Arp\LaminasDoctrine\Config\ConnectionConfigs; |
|
10
|
|
|
use Arp\LaminasDoctrine\Config\EntityManagerConfigs; |
|
11
|
|
|
use Arp\LaminasFactory\AbstractFactory; |
|
12
|
|
|
use Laminas\ServiceManager\Exception\ServiceNotCreatedException; |
|
13
|
|
|
use Laminas\ServiceManager\Exception\ServiceNotFoundException; |
|
14
|
|
|
use Psr\Container\ContainerExceptionInterface; |
|
15
|
|
|
use Psr\Container\ContainerInterface; |
|
16
|
|
|
|
|
17
|
|
|
final class DoctrineConfigFactory extends AbstractFactory |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @param array<string, mixed>|null $options |
|
21
|
|
|
* |
|
22
|
|
|
* @throws ServiceNotCreatedException |
|
23
|
|
|
* @throws ServiceNotFoundException |
|
24
|
|
|
* @throws ContainerExceptionInterface |
|
25
|
|
|
*/ |
|
26
|
|
|
public function __invoke( |
|
27
|
|
|
ContainerInterface $container, |
|
28
|
|
|
string $requestedName, |
|
29
|
|
|
array $options = null |
|
30
|
|
|
): DoctrineConfig { |
|
31
|
|
|
$options = $options ?? $this->getApplicationOptions($container, 'doctrine'); |
|
32
|
|
|
|
|
33
|
|
|
/** @var EntityManagerConfigs $entityManagerConfigs */ |
|
34
|
|
|
$entityManagerConfigs = $this->getService($container, EntityManagerConfigs::class, $requestedName); |
|
35
|
|
|
|
|
36
|
|
|
/** @var ConnectionConfigs $connectionConfigs */ |
|
37
|
|
|
$connectionConfigs = $this->getService($container, ConnectionConfigs::class, $requestedName); |
|
38
|
|
|
|
|
39
|
|
|
/** @var ConfigurationConfigs $configurationConfigs */ |
|
40
|
|
|
$configurationConfigs = $this->getService($container, ConfigurationConfigs::class, $requestedName); |
|
41
|
|
|
|
|
42
|
|
|
if (empty($options['driver'])) { |
|
43
|
|
|
throw new ServiceNotCreatedException( |
|
44
|
|
|
sprintf( |
|
45
|
|
|
'The required \'driver\' configuration key is missing for service \'%s\'', |
|
46
|
|
|
$requestedName |
|
47
|
|
|
) |
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
return new DoctrineConfig( |
|
52
|
|
|
$entityManagerConfigs, |
|
53
|
|
|
$connectionConfigs, |
|
54
|
|
|
$configurationConfigs, |
|
55
|
|
|
$options |
|
56
|
|
|
); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|