@@ -25,7 +25,6 @@ class Collection {
2525 public function __construct (Connection $ connection , MongoCollection $ collection )
2626 {
2727 $ this ->connection = $ connection ;
28-
2928 $ this ->collection = $ collection ;
3029 }
3130
@@ -38,34 +37,36 @@ public function __construct(Connection $connection, MongoCollection $collection)
3837 */
3938 public function __call ($ method , $ parameters )
4039 {
41- $ query = array ( );
40+ $ start = microtime ( true );
4241
43- // Build the query string.
44- foreach ($ parameters as $ parameter )
45- {
46- try
47- {
48- $ query [] = json_encode ($ parameter );
49- }
50- catch (Exception $ e )
51- {
52- $ query [] = '{...} ' ;
53- }
54- }
42+ $ result = call_user_func_array ([$ this ->collection , $ method ], $ parameters );
5543
56- $ start = microtime (true );
44+ if ($ this ->connection ->logging ())
45+ {
46+ // Once we have run the query we will calculate the time that it took to run and
47+ // then log the query, bindings, and execution time so we will report them on
48+ // the event that the developer needs them. We'll log time in milliseconds.
49+ $ time = $ this ->connection ->getElapsedTime ($ start );
5750
58- $ result = call_user_func_array ( array ( $ this -> collection , $ method ), $ parameters ) ;
51+ $ query = [] ;
5952
60- // Once we have run the query we will calculate the time that it took to run and
61- // then log the query, bindings, and execution time so we will report them on
62- // the event that the developer needs them. We'll log time in milliseconds.
63- $ time = $ this ->connection ->getElapsedTime ($ start );
53+ // Convert the query paramters to a json string.
54+ foreach ($ parameters as $ parameter )
55+ {
56+ try
57+ {
58+ $ query [] = json_encode ($ parameter );
59+ }
60+ catch (Exception $ e )
61+ {
62+ $ query [] = '{...} ' ;
63+ }
64+ }
6465
65- // Convert the query to a readable string.
66- $ queryString = $ this ->collection ->getName () . '. ' . $ method . '( ' . join (', ' , $ query ) . ') ' ;
66+ $ queryString = $ this ->collection ->getName () . '. ' . $ method . '( ' . join (', ' , $ query ) . ') ' ;
6767
68- $ this ->connection ->logQuery ($ queryString , array (), $ time );
68+ $ this ->connection ->logQuery ($ queryString , [], $ time );
69+ }
6970
7071 return $ result ;
7172 }
0 commit comments