Skip to content

Commit c35e322

Browse files
authored
Merge pull request #88 from neo4j-php/feat/driver-session-container-aliasing
feat: Add aliases for each driver and session
2 parents d0283a1 + 1ec5a1c commit c35e322

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

src/DependencyInjection/Neo4jExtension.php

+22
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Neo4j\Neo4jBundle\DependencyInjection;
66

7+
use Laudis\Neo4j\Contracts\DriverInterface;
8+
use Laudis\Neo4j\Contracts\SessionInterface;
79
use Neo4j\Neo4jBundle\Collector\Neo4jDataCollector;
810
use Neo4j\Neo4jBundle\EventHandler;
911
use Neo4j\Neo4jBundle\EventListener\Neo4jProfileListener;
@@ -58,6 +60,26 @@ public function load(array $configs, ContainerBuilder $container): ContainerBuil
5860
$container->getDefinition('neo4j.driver')
5961
->setArgument(0, $defaultAlias);
6062

63+
foreach ($mergedConfig['drivers'] as $driverConfig) {
64+
$container
65+
->setDefinition(
66+
'neo4j.driver.'.$driverConfig['alias'],
67+
(new Definition(DriverInterface::class))
68+
->setFactory([new Reference('neo4j.client'), 'getDriver'])
69+
->setArgument(0, $driverConfig['alias'])
70+
)
71+
->setPublic(true);
72+
73+
$container
74+
->setDefinition(
75+
'neo4j.session.'.$driverConfig['alias'],
76+
(new Definition(SessionInterface::class))
77+
->setFactory([new Reference('neo4j.driver.'.$driverConfig['alias']), 'createSession'])
78+
->setShared(false)
79+
)
80+
->setPublic(true);
81+
}
82+
6183
$enabledProfiles = [];
6284
foreach ($mergedConfig['drivers'] as $driver) {
6385
if (true === $driver['profiling'] || (null === $driver['profiling'] && $container->getParameter(

tests/App/Controller/TestController.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
use Laudis\Neo4j\Contracts\ClientInterface;
66
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
77
use Symfony\Component\HttpFoundation\Response;
8-
use Symfony\Component\HttpKernel\Profiler\Profiler;
9-
use Symfony\Component\Stopwatch\Stopwatch;
108

119
class TestController extends AbstractController
1210
{
@@ -15,7 +13,7 @@ public function __construct(
1513
) {
1614
}
1715

18-
public function __invoke(Profiler $profiler, Stopwatch $stopwatch): Response
16+
public function __invoke(): Response
1917
{
2018
// Successful statement
2119
$this->client->run('MATCH (n {foo: $bar}) RETURN n', ['bar' => 'baz']);

tests/Functional/IntegrationTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,18 @@ public function testDefaultTransactionConfig(): void
196196
$this->assertSame($transactionConfig->getTimeout(), 40.0);
197197
}
198198

199+
public function testDriverAndSessionTags(): void
200+
{
201+
static::bootKernel();
202+
$container = static::getContainer();
203+
204+
$this->assertTrue($container->has('neo4j.driver.neo4j-simple'));
205+
$this->assertTrue($container->has('neo4j.driver.neo4j-test'));
206+
207+
$this->assertTrue($container->has('neo4j.session.neo4j-simple'));
208+
$this->assertTrue($container->has('neo4j.session.neo4j-test'));
209+
}
210+
199211
public function testPriority(): void
200212
{
201213
static::bootKernel();

0 commit comments

Comments
 (0)