neo4j / neo4j-bundle
Symfony integration for Neo4j
Requires
- php: >=8.1
- ext-json: *
- laudis/neo4j-php-client: ^3.3
- symfony/config: ^6.4 || ^7.2
- symfony/dependency-injection: ^6.4 || ^7.2
- twig/twig: ^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.75
- kubawerlos/php-cs-fixer-custom-fixers: ^3.0
- matthiasnoback/symfony-dependency-injection-test: ^4.3 || ^5.0
- phpunit/phpunit: ^9.5
- psalm/plugin-phpunit: ^0.19.5
- psalm/plugin-symfony: ^5.0
- symfony/console: ^6.4 || ^7.2
- symfony/framework-bundle: ^6.4 || ^7.2
- symfony/http-kernel: ^6.4 || ^7.2
- symfony/routing: ^6.4 || ^7.2
- symfony/stopwatch: ^6.4 || ^7.2
- symfony/test-pack: ^1.1
- symfony/twig-bundle: ^6.4 || ^7.2
- symfony/uid: ^6.4 || ^7.2
- symfony/web-profiler-bundle: ^6.4 || ^7.2
- symfony/yaml: ^6.4 || ^7.2
- vimeo/psalm: ^6.11
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-17 12:05:50 UTC
README
Installation
Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.
Applications that don't use Symfony Flex
Step 1: Download the Bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require neo4j/neo4j-bundle
Step 2: Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles
in the config/bundles.php file of your project:
// config/bundles.php return [ // ... \Neo4j\Neo4jBundle\Neo4jBundle::class => ['all' => true], ];
Documentation
The bundle is a convenient way of registering services. We register Drivers and one
Clients. You will always have alias for the default services:
- neo4j.driver
- neo4j.client
Minimal configuration
neo4j: drivers: default: ~
With the minimal configuration we have services named:
- neo4j.driver.default
- neo4j.client
Full configuration example
This example configures the client to contain two instances.
neo4j: profiling: true default_driver: high-availability drivers: - alias: high-availability dsn: 'neo4j://core1.mydomain.com:7687' authentication: type: 'oidc' token: '%neo4j.openconnect-id-token%' priority: 1 # Overriding the alias makes it so that there is a backup server to use in case # the routing table cannot be fetched through the driver with a higher priority # but the same alias. # Once the table is fetched it will use that information to auto-route as usual. - alias: high-availability dsn: 'neo4j://core2.mydomain.com:7687' priority: 0 authentication: type: 'oidc' token: '%neo4j.openconnect-id-token%' - alias: backup-instance dsn: 'bolt://localhost:7687' authentication: type: basic username: '%neo4j.backup-user%' password: '%neo4j.backup-pass%'
Profiling
The bundle integrates with Symfony's profiler to collect Neo4j query data. Enable profiling by setting profiling: true on individual drivers:
neo4j: drivers: - alias: default dsn: 'bolt://neo4j:password@neo4j:7687' profiling: true
When profiling is enabled, the Neo4j data collector will track:
- Query statements and parameters
- Execution times
- Successful and failed queries
- Driver alias information
Profiling data is available in the Symfony profiler toolbar and can be accessed programmatically:
$collector = $profile->getCollector('neo4j'); $successfulStatements = $collector->getSuccessfulStatements(); $failedStatements = $collector->getFailedStatements(); $queryCount = $collector->getQueryCount();
Testing
Run all tests:
$ composer test
Run only unit tests:
$ composer test:unit
Run only functional tests:
$ composer test:functional
For functional tests that require a Neo4j server, ensure Neo4j is running and accessible. When running tests in Docker, the Neo4j service name should match your DSN configuration.
Example application
See an example application at https://github.com/neo4j-examples/movies-symfony-php-bolt (legacy project)
License
The MIT License (MIT). Please see License File for more information.