1 | <?php |
||
20 | class DBALConfigurationFactory implements FactoryInterface |
||
21 | { |
||
22 | /** |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $name; |
||
26 | |||
27 | /** |
||
28 | * @param string $name |
||
29 | */ |
||
30 | 88 | public function __construct($name) |
|
34 | |||
35 | /** |
||
36 | * {@inheritDoc} |
||
37 | * |
||
38 | * @return \Doctrine\DBAL\Configuration |
||
39 | */ |
||
40 | public function __invoke(ContainerInterface $container, $requestedName, array $options = null) |
||
47 | |||
48 | /** |
||
49 | * {@inheritDoc} |
||
50 | * @return \Doctrine\DBAL\Configuration |
||
51 | */ |
||
52 | public function createService(ServiceLocatorInterface $container) |
||
56 | |||
57 | /** |
||
58 | * @param ContainerInterface $container |
||
59 | * @param Configuration $config |
||
60 | */ |
||
61 | 86 | public function setupDBALConfiguration(ContainerInterface $container, Configuration $config) |
|
62 | { |
||
63 | 86 | $options = $this->getOptions($container); |
|
64 | 86 | $config->setResultCacheImpl($container->get($options->resultCache)); |
|
65 | |||
66 | 86 | $sqlLogger = $options->sqlLogger; |
|
67 | 86 | if (is_string($sqlLogger) and $container->has($sqlLogger)) { |
|
68 | $sqlLogger = $container->get($sqlLogger); |
||
69 | } |
||
70 | 86 | $config->setSQLLogger($sqlLogger); |
|
71 | |||
72 | 86 | foreach ($options->types as $name => $class) { |
|
73 | if (Type::hasType($name)) { |
||
74 | Type::overrideType($name, $class); |
||
75 | } else { |
||
76 | Type::addType($name, $class); |
||
77 | } |
||
78 | } |
||
79 | 86 | } |
|
80 | |||
81 | /** |
||
82 | * @param ContainerInterface $serviceLocator |
||
83 | * @return mixed |
||
84 | * @throws RuntimeException |
||
85 | */ |
||
86 | 88 | public function getOptions(ContainerInterface $serviceLocator) |
|
87 | { |
||
88 | 88 | $options = $serviceLocator->get('config'); |
|
89 | 88 | $options = $options['doctrine']; |
|
90 | 88 | $options = $options['configuration'][$this->name] ?? null; |
|
91 | |||
92 | 88 | if (null === $options) { |
|
93 | throw new RuntimeException( |
||
94 | sprintf( |
||
95 | 'Configuration with name "%s" could not be found in "doctrine.configuration".', |
||
96 | $this->name |
||
97 | ) |
||
98 | ); |
||
99 | } |
||
100 | |||
101 | 88 | $optionsClass = $this->getOptionsClass(); |
|
102 | |||
103 | 88 | return new $optionsClass($options); |
|
104 | } |
||
105 | |||
106 | /** |
||
107 | * @return string |
||
108 | */ |
||
109 | protected function getOptionsClass() |
||
113 | } |
||
114 |