1 | <?php |
||
14 | final class DoctrineMongoServiceProvider implements ServiceProviderInterface |
||
15 | { |
||
16 | /** |
||
17 | * @param Container $container |
||
18 | */ |
||
19 | 3 | public function register(Container $container) |
|
32 | |||
33 | /** |
||
34 | * @return array |
||
35 | */ |
||
36 | 3 | private function getMongoDbDefaultOptions(): array |
|
44 | |||
45 | /** |
||
46 | * @param Container $container |
||
47 | * |
||
48 | * @return callable |
||
49 | */ |
||
50 | private function getMongoDbsOptionsInitializerDefinition(Container $container): callable |
||
51 | { |
||
52 | 3 | return $container->protect(function () use ($container) { |
|
53 | 3 | static $initialized = false; |
|
54 | |||
55 | 3 | if ($initialized) { |
|
56 | 3 | return; |
|
57 | } |
||
58 | |||
59 | 3 | $initialized = true; |
|
60 | |||
61 | 3 | if (!isset($container['doctrine.mongo.dbs.options'])) { |
|
62 | 2 | $container['doctrine.mongo.dbs.options'] = [ |
|
63 | 2 | 'default' => isset($container['doctrine.mongo.db.options']) ? $container['doctrine.mongo.db.options'] : [], |
|
64 | ]; |
||
65 | } |
||
66 | |||
67 | 3 | $tmp = $container['doctrine.mongo.dbs.options']; |
|
68 | 3 | foreach ($tmp as $name => &$options) { |
|
69 | 3 | $options = array_replace_recursive($container['doctrine.mongo.db.default_options'], $options); |
|
70 | |||
71 | 3 | if (!isset($container['doctrine.mongo.dbs.default'])) { |
|
72 | 3 | $container['doctrine.mongo.dbs.default'] = $name; |
|
73 | } |
||
74 | } |
||
75 | |||
76 | 3 | $container['doctrine.mongo.dbs.options'] = $tmp; |
|
77 | 3 | }); |
|
78 | } |
||
79 | |||
80 | /** |
||
81 | * @param Container $container |
||
82 | * |
||
83 | * @return callable |
||
84 | */ |
||
85 | private function getMongoDbsDefinition(Container $container): callable |
||
109 | |||
110 | /** |
||
111 | * @param Container $container |
||
112 | * |
||
113 | * @return callable |
||
114 | */ |
||
115 | private function getMongoDbsConfigDefinition(Container $container): callable |
||
142 | |||
143 | /** |
||
144 | * @param Container $container |
||
145 | * |
||
146 | * @return callable |
||
147 | */ |
||
148 | private function getMongoDbsEventManagerDefinition(Container $container): callable |
||
149 | { |
||
150 | 3 | return function () use ($container) { |
|
151 | 3 | $container['doctrine.mongo.dbs.options.initializer'](); |
|
152 | |||
153 | 3 | $managers = new Container(); |
|
154 | 3 | foreach ($container['doctrine.mongo.dbs.options'] as $name => $options) { |
|
155 | 3 | $managers[$name] = function () { |
|
156 | 3 | return new EventManager(); |
|
157 | 3 | }; |
|
158 | } |
||
159 | |||
160 | 3 | return $managers; |
|
161 | 3 | }; |
|
162 | } |
||
163 | |||
164 | /*** |
||
165 | * @param Container $container |
||
166 | * @return callable |
||
167 | */ |
||
168 | private function getMongoDbDefinition(Container $container): callable |
||
176 | |||
177 | /*** |
||
178 | * @param Container $container |
||
179 | * @return callable |
||
180 | */ |
||
181 | private function getMongoDbConfigDefinition(Container $container): callable |
||
189 | |||
190 | /*** |
||
191 | * @param Container $container |
||
192 | * @return callable |
||
193 | */ |
||
194 | private function getMongoDbEventManagerDefinition(Container $container): callable |
||
202 | } |
||
203 |