1010namespace Nette \Database ;
1111
1212use Nette ;
13+ use Nette \Utils \Arrays ;
1314use PDO ;
1415use PDOException ;
1516
@@ -22,10 +23,10 @@ class Connection
2223 use Nette \SmartObject;
2324
2425 /** @var callable[]&(callable(Connection $connection): void)[]; Occurs after connection is established */
25- public $ onConnect ;
26+ public $ onConnect = [] ;
2627
2728 /** @var callable[]&(callable(Connection $connection, ResultSet|DriverException $result): void)[]; Occurs after query is executed */
28- public $ onQuery ;
29+ public $ onQuery = [] ;
2930
3031 /** @var array */
3132 private $ params ;
@@ -76,7 +77,7 @@ public function connect(): void
7677 $ this ->driver = new $ class ;
7778 $ this ->preprocessor = new SqlPreprocessor ($ this );
7879 $ this ->driver ->initialize ($ this , $ this ->options );
79- $ this ->onConnect ( $ this );
80+ Arrays:: invoke ( $ this ->onConnect , $ this );
8081 }
8182
8283
@@ -186,10 +187,10 @@ public function query(string $sql, ...$params): ResultSet
186187 try {
187188 $ result = new ResultSet ($ this , $ this ->sql , $ params );
188189 } catch (PDOException $ e ) {
189- $ this ->onQuery ( $ this , $ e );
190+ Arrays:: invoke ( $ this ->onQuery , $ this , $ e );
190191 throw $ e ;
191192 }
192- $ this ->onQuery ( $ this , $ result );
193+ Arrays:: invoke ( $ this ->onQuery , $ this , $ result );
193194 return $ result ;
194195 }
195196
0 commit comments