@@ -25,7 +25,6 @@ class Collection {
25
25
public function __construct (Connection $ connection , MongoCollection $ collection )
26
26
{
27
27
$ this ->connection = $ connection ;
28
-
29
28
$ this ->collection = $ collection ;
30
29
}
31
30
@@ -38,34 +37,36 @@ public function __construct(Connection $connection, MongoCollection $collection)
38
37
*/
39
38
public function __call ($ method , $ parameters )
40
39
{
41
- $ query = array ( );
40
+ $ start = microtime ( true );
42
41
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 );
55
43
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 );
57
50
58
- $ result = call_user_func_array ( array ( $ this -> collection , $ method ), $ parameters ) ;
51
+ $ query = [] ;
59
52
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
+ }
64
65
65
- // Convert the query to a readable string.
66
- $ queryString = $ this ->collection ->getName () . '. ' . $ method . '( ' . join (', ' , $ query ) . ') ' ;
66
+ $ queryString = $ this ->collection ->getName () . '. ' . $ method . '( ' . join (', ' , $ query ) . ') ' ;
67
67
68
- $ this ->connection ->logQuery ($ queryString , array (), $ time );
68
+ $ this ->connection ->logQuery ($ queryString , [], $ time );
69
+ }
69
70
70
71
return $ result ;
71
72
}
0 commit comments