1 | <?php |
||
23 | class Neo4jExtension extends Extension |
||
24 | { |
||
25 | /** |
||
26 | * {@inheritdoc} |
||
27 | */ |
||
28 | 4 | public function load(array $configs, ContainerBuilder $container) |
|
54 | |||
55 | /** |
||
56 | * {@inheritdoc} |
||
57 | */ |
||
58 | 4 | public function getConfiguration(array $config, ContainerBuilder $container): Configuration |
|
62 | |||
63 | /** |
||
64 | * {@inheritdoc} |
||
65 | */ |
||
66 | 4 | public function getAlias(): string |
|
70 | |||
71 | /** |
||
72 | * @param array $config |
||
73 | * @param ContainerBuilder $container |
||
74 | * |
||
75 | * @return array with service ids |
||
76 | */ |
||
77 | 4 | private function handleClients(array &$config, ContainerBuilder $container): array |
|
78 | { |
||
79 | 4 | if (empty($config['clients'])) { |
|
80 | // Add default entity manager if none set. |
||
81 | 4 | $config['clients']['default'] = ['connections' => ['default']]; |
|
82 | } |
||
83 | |||
84 | 4 | $serviceIds = []; |
|
85 | 4 | foreach ($config['clients'] as $name => $data) { |
|
86 | 4 | $connections = []; |
|
87 | 4 | $serviceIds[$name] = $serviceId = sprintf('neo4j.client.%s', $name); |
|
88 | 4 | foreach ($data['connections'] as $connectionName) { |
|
89 | 4 | if (empty($config['connections'][$connectionName])) { |
|
90 | throw new InvalidConfigurationException(sprintf( |
||
91 | 'Client "%s" is configured to use connection named "%s" but there is no such connection', |
||
92 | $name, |
||
93 | $connectionName |
||
94 | )); |
||
95 | } |
||
96 | 4 | $connections[] = $connectionName; |
|
97 | } |
||
98 | 4 | if (empty($connections)) { |
|
99 | $connections[] = 'default'; |
||
100 | } |
||
101 | |||
102 | $container |
||
103 | 4 | ->setDefinition($serviceId, new DefinitionDecorator('neo4j.client.abstract')) |
|
|
|||
104 | 4 | ->setArguments([$connections]); |
|
105 | } |
||
106 | |||
107 | 4 | return $serviceIds; |
|
108 | } |
||
109 | |||
110 | /** |
||
111 | * @param array $config |
||
112 | * @param ContainerBuilder $container |
||
113 | * @param array $clientServiceIds |
||
114 | * |
||
115 | * @return array |
||
116 | */ |
||
117 | 4 | private function handleEntityMangers(array &$config, ContainerBuilder $container, array $clientServiceIds): array |
|
118 | { |
||
119 | 4 | $serviceIds = []; |
|
120 | 4 | foreach ($config['entity_managers'] as $name => $data) { |
|
121 | 4 | $serviceIds[] = $serviceId = sprintf('neo4j.entity_manager.%s', $name); |
|
122 | 4 | $clientName = $data['client']; |
|
123 | 4 | if (empty($clientServiceIds[$clientName])) { |
|
124 | throw new InvalidConfigurationException(sprintf( |
||
125 | 'EntityManager "%s" is configured to use client named "%s" but there is no such client', |
||
126 | $name, |
||
127 | $clientName |
||
128 | )); |
||
129 | } |
||
130 | $container |
||
131 | 4 | ->setDefinition($serviceId, new DefinitionDecorator('neo4j.entity_manager.abstract')) |
|
132 | 4 | ->setArguments([ |
|
133 | 4 | $container->getDefinition($clientServiceIds[$clientName]), |
|
134 | 4 | empty($data['cache_dir']) ? $container->getParameter('kernel.cache_dir').'/neo4j' : $data['cache_dir'], |
|
135 | ]); |
||
136 | } |
||
137 | |||
138 | 4 | return $serviceIds; |
|
139 | } |
||
140 | |||
141 | /** |
||
142 | * @param array $config |
||
143 | * @param ContainerBuilder $container |
||
144 | * |
||
145 | * @return array with service ids |
||
146 | */ |
||
147 | 4 | private function handleConnections(array &$config, ContainerBuilder $container): array |
|
176 | |||
177 | /** |
||
178 | * Get URL form config. |
||
179 | * |
||
180 | * @param array $config |
||
181 | * |
||
182 | * @return string |
||
183 | */ |
||
184 | 4 | private function getUrl(array $config): string |
|
195 | |||
196 | /** |
||
197 | * Return the correct default port if not manually set. |
||
198 | * |
||
199 | * @param array $config |
||
200 | * |
||
201 | * @return int |
||
202 | */ |
||
203 | 4 | private function getPort(array $config) |
|
211 | |||
212 | /** |
||
213 | * Make sure the EntityManager is installed if we have configured it. |
||
214 | * |
||
215 | * @param array &$config |
||
216 | * |
||
217 | * @return bool true if "graphaware/neo4j-php-ogm" is installed |
||
218 | * |
||
219 | * @thorws \LogicException if EntityManagers os not installed but they are configured. |
||
220 | */ |
||
221 | 4 | private function validateEntityManagers(array &$config): bool |
|
237 | } |
||
238 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.