diff --git a/src/DependencyInjection/Neo4jExtension.php b/src/DependencyInjection/Neo4jExtension.php index d366309..339bf49 100644 --- a/src/DependencyInjection/Neo4jExtension.php +++ b/src/DependencyInjection/Neo4jExtension.php @@ -4,6 +4,8 @@ namespace Neo4j\Neo4jBundle\DependencyInjection; +use Laudis\Neo4j\Contracts\DriverInterface; +use Laudis\Neo4j\Contracts\SessionInterface; use Neo4j\Neo4jBundle\Collector\Neo4jDataCollector; use Neo4j\Neo4jBundle\EventHandler; use Neo4j\Neo4jBundle\EventListener\Neo4jProfileListener; @@ -58,6 +60,26 @@ public function load(array $configs, ContainerBuilder $container): ContainerBuil $container->getDefinition('neo4j.driver') ->setArgument(0, $defaultAlias); + foreach ($mergedConfig['drivers'] as $driverConfig) { + $container + ->setDefinition( + 'neo4j.driver.'.$driverConfig['alias'], + (new Definition(DriverInterface::class)) + ->setFactory([new Reference('neo4j.client'), 'getDriver']) + ->setArgument(0, $driverConfig['alias']) + ) + ->setPublic(true); + + $container + ->setDefinition( + 'neo4j.session.'.$driverConfig['alias'], + (new Definition(SessionInterface::class)) + ->setFactory([new Reference('neo4j.driver.'.$driverConfig['alias']), 'createSession']) + ->setShared(false) + ) + ->setPublic(true); + } + $enabledProfiles = []; foreach ($mergedConfig['drivers'] as $driver) { if (true === $driver['profiling'] || (null === $driver['profiling'] && $container->getParameter( diff --git a/tests/App/Controller/TestController.php b/tests/App/Controller/TestController.php index 98969b0..63397e5 100644 --- a/tests/App/Controller/TestController.php +++ b/tests/App/Controller/TestController.php @@ -5,8 +5,6 @@ use Laudis\Neo4j\Contracts\ClientInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Profiler\Profiler; -use Symfony\Component\Stopwatch\Stopwatch; class TestController extends AbstractController { @@ -15,7 +13,7 @@ public function __construct( ) { } - public function __invoke(Profiler $profiler, Stopwatch $stopwatch): Response + public function __invoke(): Response { // Successful statement $this->client->run('MATCH (n {foo: $bar}) RETURN n', ['bar' => 'baz']); diff --git a/tests/Functional/IntegrationTest.php b/tests/Functional/IntegrationTest.php index ece543a..8020681 100644 --- a/tests/Functional/IntegrationTest.php +++ b/tests/Functional/IntegrationTest.php @@ -196,6 +196,18 @@ public function testDefaultTransactionConfig(): void $this->assertSame($transactionConfig->getTimeout(), 40.0); } + public function testDriverAndSessionTags(): void + { + static::bootKernel(); + $container = static::getContainer(); + + $this->assertTrue($container->has('neo4j.driver.neo4j-simple')); + $this->assertTrue($container->has('neo4j.driver.neo4j-test')); + + $this->assertTrue($container->has('neo4j.session.neo4j-simple')); + $this->assertTrue($container->has('neo4j.session.neo4j-test')); + } + public function testPriority(): void { static::bootKernel();