Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/DependencyInjection/Neo4jExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 1 addition & 3 deletions tests/App/Controller/TestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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']);
Expand Down
12 changes: 12 additions & 0 deletions tests/Functional/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading