|
6 | 6 |
|
7 | 7 | use GraphAware\Bolt\Driver as BoltDriver; |
8 | 8 | use GraphAware\Neo4j\Client\Connection\Connection; |
| 9 | +use GraphAware\Neo4j\OGM\EntityManager; |
9 | 10 | use GraphAware\Neo4j\Client\HttpDriver\Driver as HttpDriver; |
10 | 11 | use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; |
11 | 12 | use Symfony\Component\Config\FileLocator; |
@@ -34,7 +35,10 @@ public function load(array $configs, ContainerBuilder $container) |
34 | 35 |
|
35 | 36 | $this->handleConnections($config, $container); |
36 | 37 | $clientServiceIds = $this->handleClients($config, $container); |
37 | | - $this->handleEntityMangers($config, $container, $clientServiceIds); |
| 38 | + if ($this->validateEntityManagers($config)) { |
| 39 | + $loader->load('entity_manager.xml'); |
| 40 | + $this->handleEntityMangers($config, $container, $clientServiceIds); |
| 41 | + } |
38 | 42 |
|
39 | 43 | // add aliases for the default services |
40 | 44 | $container->setAlias('neo4j.connection', 'neo4j.connection.default'); |
@@ -114,11 +118,6 @@ private function handleClients(array &$config, ContainerBuilder $container): arr |
114 | 118 | */ |
115 | 119 | private function handleEntityMangers(array &$config, ContainerBuilder $container, array $clientServiceIds): array |
116 | 120 | { |
117 | | - if (empty($config['entity_managers'])) { |
118 | | - // Add default entity manager if none set. |
119 | | - $config['entity_managers']['default'] = ['client' => 'default']; |
120 | | - } |
121 | | - |
122 | 121 | $serviceIds = []; |
123 | 122 | foreach ($config['entity_managers'] as $name => $data) { |
124 | 123 | $serviceIds[] = $serviceId = sprintf('neo4j.entity_manager.%s', $name); |
@@ -204,4 +203,30 @@ private function getPort(array $config) |
204 | 203 |
|
205 | 204 | return 'http' == $config['schema'] ? HttpDriver::DEFAULT_HTTP_PORT : BoltDriver::DEFAULT_TCP_PORT; |
206 | 205 | } |
| 206 | + |
| 207 | + /** |
| 208 | + * Make sure the EntityManager is installed if we have configured it. |
| 209 | + * |
| 210 | + * @param array &$config |
| 211 | + * |
| 212 | + * @return bool true if "graphaware/neo4j-php-ogm" is installed |
| 213 | + * |
| 214 | + * @thorws \LogicException if EntityManagers os not installed but they are configured. |
| 215 | + */ |
| 216 | + private function validateEntityManagers(array &$config): bool |
| 217 | + { |
| 218 | + $dependenciesInstalled = class_exists(EntityManager::class); |
| 219 | + $entityManagersConfigured = !empty($config['entity_managers']); |
| 220 | + |
| 221 | + if ($dependenciesInstalled && !$entityManagersConfigured) { |
| 222 | + // Add default entity manager if none set. |
| 223 | + $config['entity_managers']['default'] = ['client' => 'default']; |
| 224 | + } elseif (!$dependenciesInstalled && $entityManagersConfigured) { |
| 225 | + throw new \LogicException( |
| 226 | + 'You need to install "graphaware/neo4j-php-ogm" to be able to use the EntityManager' |
| 227 | + ); |
| 228 | + } |
| 229 | + |
| 230 | + return $dependenciesInstalled; |
| 231 | + } |
207 | 232 | } |
0 commit comments