1313
1414use GraphAware \Common \Cypher \Statement ;
1515use GraphAware \Common \Transaction \TransactionInterface ;
16+ use GraphAware \Neo4j \Client \Event \PostRunEvent ;
17+ use GraphAware \Neo4j \Client \Event \PreRunEvent ;
18+ use GraphAware \Neo4j \Client \Neo4jClientEvents ;
19+ use GraphAware \Neo4j \Client \Result \ResultCollection ;
1620use GraphAware \Neo4j \Client \StackInterface ;
21+ use Symfony \Component \EventDispatcher \EventDispatcherInterface ;
1722
1823class Transaction
1924{
@@ -27,12 +32,19 @@ class Transaction
2732 */
2833 protected $ queue = [];
2934
35+ /**
36+ * @var EventDispatcherInterface
37+ */
38+ protected $ eventDispatcher ;
39+
3040 /**
3141 * @param TransactionInterface $driverTransaction
42+ * @param EventDispatcherInterface $eventDispatcher
3243 */
33- public function __construct (TransactionInterface $ driverTransaction )
44+ public function __construct (TransactionInterface $ driverTransaction, EventDispatcherInterface $ eventDispatcher )
3445 {
3546 $ this ->driverTransaction = $ driverTransaction ;
47+ $ this ->eventDispatcher = $ eventDispatcher ;
3648 }
3749
3850 /**
@@ -59,8 +71,12 @@ public function run($statement, array $parameters = [], $tag = null)
5971 if (!$ this ->driverTransaction ->isOpen () && !in_array ($ this ->driverTransaction ->status (), ['COMMITED ' , 'ROLLED_BACK ' ], true )) {
6072 $ this ->driverTransaction ->begin ();
6173 }
74+ $ statement = Statement::create ($ statement , $ parameters , $ tag );
75+ $ this ->eventDispatcher ->dispatch (Neo4jClientEvents::NEO4J_PRE_RUN , new PreRunEvent ([$ statement ]));
76+ $ result = $ this ->driverTransaction ->run (Statement::create ($ statement , $ parameters , $ tag ));
77+ $ this ->eventDispatcher ->dispatch (Neo4jClientEvents::NEO4J_POST_RUN , new PostRunEvent (ResultCollection::withResult ($ result )));
6278
63- return $ this -> driverTransaction -> run (Statement:: create ( $ statement , $ parameters , $ tag )) ;
79+ return $ result ;
6480 }
6581
6682 /**
@@ -90,7 +106,11 @@ public function runStack(StackInterface $stack)
90106 $ sts [] = $ statement ;
91107 }
92108
93- return $ this ->driverTransaction ->runMultiple ($ sts );
109+ $ this ->eventDispatcher ->dispatch (Neo4jClientEvents::NEO4J_PRE_RUN , new PreRunEvent ($ stack ->statements ()));
110+ $ results = $ this ->driverTransaction ->runMultiple ($ sts );
111+ $ this ->eventDispatcher ->dispatch (Neo4jClientEvents::NEO4J_POST_RUN , new PostRunEvent ($ results ));
112+
113+ return $ results ;
94114 }
95115
96116 public function begin ()
0 commit comments