diff --git a/config/services.php b/config/services.php index 8ec9920..2e78d3a 100644 --- a/config/services.php +++ b/config/services.php @@ -48,7 +48,4 @@ $services->alias(DriverInterface::class, 'neo4j.driver'); $services->alias(SessionInterface::class, 'neo4j.session'); $services->alias(TransactionInterface::class, 'neo4j.transaction'); - - $services->set('neo4j.subscriber', Neo4jProfileListener::class) - ->tag('kernel.event_subscriber'); }; diff --git a/src/Collector/Neo4jDataCollector.php b/src/Collector/Neo4jDataCollector.php deleted file mode 100644 index 2e3f739..0000000 --- a/src/Collector/Neo4jDataCollector.php +++ /dev/null @@ -1,83 +0,0 @@ ->, - * failed_statements: list - * } $data - */ -final class Neo4jDataCollector extends AbstractDataCollector -{ - public function __construct( - private Neo4jProfileListener $subscriber - ) { - } - - public function collect(Request $request, Response $response, ?\Throwable $exception = null): void - { - $this->data['successful_statements'] = array_map( - static fn (ResultSummary $summary) => $summary->toArray(), - $this->subscriber->getProfiledSummaries() - ); - - $this->data['failed_statements'] = array_map( - static fn (array $x) => [ - 'statement' => $x['statement']->toArray(), - 'exception' => [ - 'code' => $x['exception']->getErrors()[0]->getCode(), - 'message' => $x['exception']->getErrors()[0]->getMessage(), - 'classification' => $x['exception']->getErrors()[0]->getClassification(), - 'category' => $x['exception']->getErrors()[0]->getCategory(), - 'title' => $x['exception']->getErrors()[0]->getTitle(), - ], - 'alias' => $x['alias'], - ], - $this->subscriber->getProfiledFailures() - ); - } - - public function reset(): void - { - parent::reset(); - $this->subscriber->reset(); - } - - public function getName(): string - { - return 'neo4j'; - } - - public function getFailedStatements(): array - { - return $this->data['failed_statements']; - } - - public function getSuccessfulStatements(): array - { - return $this->data['successful_statements']; - } - - public function getQueryCount(): int - { - return count($this->data['successful_statements']) + count($this->data['failed_statements']); - } - - public static function getTemplate(): ?string - { - return 'web_profiler.html.twig'; - } -} diff --git a/src/Collector/Twig/Neo4jResultExtension.php b/src/Collector/Twig/Neo4jResultExtension.php deleted file mode 100644 index 20277f1..0000000 --- a/src/Collector/Twig/Neo4jResultExtension.php +++ /dev/null @@ -1,56 +0,0 @@ - - */ -class Neo4jResultExtension extends AbstractExtension -{ - /** - * @return array - */ - public function getFilters(): array - { - return [ - new TwigFilter('neo4jResult', [$this, 'getType']), - ]; - } - - public function getType(mixed $object): string - { - return $this->doGetType($object, true); - } - - public function getName(): string - { - return 'neo4j.result'; - } - - private function doGetType(mixed $object, bool $recursive): string - { - if ($object instanceof Node) { - return sprintf('%s: %s', $object->getId(), $object->getLabels()->join(', ')); - } - - if (is_array($object) && $recursive) { - if (empty($object)) { - return 'Empty array'; - } - $ret = []; - foreach ($object as $o) { - $ret[] = $this->doGetType($o, false); - } - - return sprintf('[%s]', implode(', ', $ret)); - } - - return get_debug_type($object); - } -} diff --git a/src/DependencyInjection/Neo4jExtension.php b/src/DependencyInjection/Neo4jExtension.php index f8617ae..5283723 100644 --- a/src/DependencyInjection/Neo4jExtension.php +++ b/src/DependencyInjection/Neo4jExtension.php @@ -12,7 +12,6 @@ use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Extension\Extension; use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; use Symfony\Component\DependencyInjection\Reference; @@ -52,20 +51,6 @@ public function load(array $configs, ContainerBuilder $container): ContainerBuil } } - if (0 !== count($enabledProfiles)) { - $container->setDefinition('neo4j.data_collector', (new Definition(Neo4jDataCollector::class)) - ->setAutowired(true) - ->addTag('data_collector') - ); - - $container->setAlias(Neo4jProfileListener::class, 'neo4j.subscriber'); - - $container->setDefinition('neo4j.subscriber', (new Definition(Neo4jProfileListener::class)) - ->setArgument(0, $enabledProfiles) - ->addTag('kernel.event_subscriber') - ); - } - return $container; } diff --git a/src/Event/FailureEvent.php b/src/Event/FailureEvent.php deleted file mode 100644 index 2981193..0000000 --- a/src/Event/FailureEvent.php +++ /dev/null @@ -1,45 +0,0 @@ -exception; - } - - public function disableException(): void - { - $this->shouldThrowException = false; - } - - public function shouldThrowException(): bool - { - return $this->shouldThrowException; - } - - public function getAlias(): ?string - { - return $this->alias; - } - - public function getStatement(): Statement - { - return $this->statement; - } -} diff --git a/src/Event/PostRunEvent.php b/src/Event/PostRunEvent.php deleted file mode 100644 index b0bf84b..0000000 --- a/src/Event/PostRunEvent.php +++ /dev/null @@ -1,29 +0,0 @@ -result; - } - - public function getAlias(): ?string - { - return $this->alias; - } -} diff --git a/src/Event/PreRunEvent.php b/src/Event/PreRunEvent.php deleted file mode 100644 index 6ab3f4d..0000000 --- a/src/Event/PreRunEvent.php +++ /dev/null @@ -1,27 +0,0 @@ -statement; - } - - public function getAlias(): ?string - { - return $this->alias; - } -} diff --git a/src/EventListener/Neo4jProfileListener.php b/src/EventListener/Neo4jProfileListener.php deleted file mode 100644 index b046b99..0000000 --- a/src/EventListener/Neo4jProfileListener.php +++ /dev/null @@ -1,78 +0,0 @@ - - */ - private array $profiledSummaries = []; - - /** - * @var list - */ - private array $profiledFailures = []; - - /** - * @param list $enabledProfiles - */ - public function __construct(private array $enabledProfiles = []) - { - } - - public static function getSubscribedEvents(): array - { - return [ - PostRunEvent::EVENT_ID => 'onPostRun', - FailureEvent::EVENT_ID => 'onFailure', - ]; - } - - public function onPostRun(PostRunEvent $event): void - { - if (in_array($event->getAlias(), $this->enabledProfiles)) { - $this->profiledSummaries[] = $event->getResult(); - } - } - - public function onFailure(FailureEvent $event): void - { - if (in_array($event->getAlias(), $this->enabledProfiles)) { - $this->profiledFailures[] = [ - 'exception' => $event->getException(), - 'statement' => $event->getStatement(), - 'alias' => $event->getAlias(), - ]; - } - } - - public function getProfiledSummaries(): array - { - return $this->profiledSummaries; - } - - /** - * @return list - */ - public function getProfiledFailures(): array - { - return $this->profiledFailures; - } - - public function reset(): void - { - $this->profiledFailures = []; - $this->profiledSummaries = []; - } -} diff --git a/tests/Unit/Collector/Twig/Neo4jResultExtensionTest.php b/tests/Unit/Collector/Twig/Neo4jResultExtensionTest.php deleted file mode 100644 index 07bc8f6..0000000 --- a/tests/Unit/Collector/Twig/Neo4jResultExtensionTest.php +++ /dev/null @@ -1,65 +0,0 @@ - - */ -class Neo4jResultExtensionTest extends TestCase -{ - public function testEmptyArray(): void - { - $o = new Neo4jResultExtension(); - $result = $o->getType([]); - - $this->assertEquals('Empty array', $result); - } - - public function testObject(): void - { - $o = new Neo4jResultExtension(); - $result = $o->getType($o); - - $this->assertEquals(Neo4jResultExtension::class, $result); - } - - public function testScalar(): void - { - $o = new Neo4jResultExtension(); - $result = $o->getType(3); - - $this->assertEquals('int', $result); - } - - public function testScalarArray(): void - { - $o = new Neo4jResultExtension(); - $result = $o->getType([3, 6.3]); - - $this->assertEquals('[int, float]', $result); - } - - public function testArrayArray(): void - { - $o = new Neo4jResultExtension(); - $result = $o->getType([[]]); - - $this->assertEquals('[array]', $result); - } - - public function testNode(): void - { - $o = new Neo4jResultExtension(); - $result = $o->getType(new Node(1, new CypherList(['Label']), new CypherMap(), null)); - - $this->assertEquals('1: Label', $result); - } -} diff --git a/tests/Unit/DependencyInjection/Neo4jExtensionTest.php b/tests/Unit/DependencyInjection/Neo4jExtensionTest.php deleted file mode 100644 index 572535d..0000000 --- a/tests/Unit/DependencyInjection/Neo4jExtensionTest.php +++ /dev/null @@ -1,57 +0,0 @@ - - */ -class Neo4jExtensionTest extends AbstractExtensionTestCase -{ - protected function getMinimalConfiguration(): array - { - $this->setParameter('kernel.cache_dir', 'foo'); - - return ['drivers' => ['default' => ['dsn' => 'bolt://localhost']]]; - } - - public function testDataCollectorLoaded(): void - { - $this->setParameter('kernel.debug', true); - $this->load(); - - $this->assertContainerBuilderHasService('neo4j.data_collector', Neo4jDataCollector::class); - } - - public function testDataCollectorNotLoadedInNonDebug(): void - { - $this->setParameter('kernel.debug', false); - $this->load(); - - $this->assertContainerBuilderNotHasService('neo4j.data_collector'); - } - - public function testDataCollectorNotLoadedWhenDisabled(): void - { - $this->setParameter('kernel.debug', true); - $this->load(['drivers' => [ - 'default' => [ - 'profiling' => false, - ], - ]]); - - $this->assertContainerBuilderNotHasService('neo4j.neo4j_data_collector'); - } - - protected function getContainerExtensions(): array - { - return [ - new Neo4jExtension(), - ]; - } -}