|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Cerbero\SqlDumper\Dumpers; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Log; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* The log dumper. |
|
9
|
|
|
* |
|
10
|
|
|
*/ |
|
11
|
|
|
class LogDumper implements DumperInterface |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* Add the given query to dump |
|
15
|
|
|
* |
|
16
|
|
|
* @param string $query |
|
17
|
|
|
* @return DumperInterface |
|
18
|
|
|
*/ |
|
19
|
6 |
|
public function addQuery(string $query): DumperInterface |
|
20
|
|
|
{ |
|
21
|
6 |
|
Log::debug("Query: {$query}"); |
|
22
|
|
|
|
|
23
|
6 |
|
return $this; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Add the query execution time to dump |
|
28
|
|
|
* |
|
29
|
|
|
* @param float $milliseconds |
|
30
|
|
|
* @return DumperInterface |
|
31
|
|
|
*/ |
|
32
|
6 |
|
public function addTime(float $milliseconds): DumperInterface |
|
33
|
|
|
{ |
|
34
|
6 |
|
$seconds = $milliseconds / 1000; |
|
35
|
|
|
|
|
36
|
6 |
|
Log::debug("Execution time in seconds: {$seconds}"); |
|
37
|
|
|
|
|
38
|
6 |
|
return $this; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Add the query caller to dump |
|
43
|
|
|
* |
|
44
|
|
|
* @param string $file |
|
45
|
|
|
* @param int $line |
|
46
|
|
|
* @return DumperInterface |
|
47
|
|
|
*/ |
|
48
|
6 |
|
public function addCaller(string $file, int $line): DumperInterface |
|
49
|
|
|
{ |
|
50
|
6 |
|
Log::debug("Executed in file {$file} on line {$line}"); |
|
51
|
|
|
|
|
52
|
6 |
|
return $this; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Add the given explanation rows to dump |
|
57
|
|
|
* |
|
58
|
|
|
* @param array $explanationRows |
|
59
|
|
|
* @return DumperInterface |
|
60
|
|
|
*/ |
|
61
|
6 |
|
public function addExplanations(array $explanationRows): DumperInterface |
|
62
|
|
|
{ |
|
63
|
6 |
|
$context = array_map('get_object_vars', $explanationRows); |
|
64
|
|
|
|
|
65
|
6 |
|
Log::debug('Explanations', $context); |
|
66
|
|
|
|
|
67
|
6 |
|
return $this; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Add a separator |
|
72
|
|
|
* |
|
73
|
|
|
* @return DumperInterface |
|
74
|
|
|
*/ |
|
75
|
6 |
|
public function addSeparator(): DumperInterface |
|
76
|
|
|
{ |
|
77
|
6 |
|
Log::debug(null); |
|
78
|
|
|
|
|
79
|
6 |
|
return $this; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Add the execution time of all queries to dump |
|
84
|
|
|
* |
|
85
|
|
|
* @param float $milliseconds |
|
86
|
|
|
* @return DumperInterface |
|
87
|
|
|
*/ |
|
88
|
6 |
|
public function addTotalTime(float $milliseconds): DumperInterface |
|
89
|
|
|
{ |
|
90
|
6 |
|
$seconds = $milliseconds / 1000; |
|
91
|
|
|
|
|
92
|
6 |
|
Log::debug("Total queries execution time in seconds: {$seconds}"); |
|
93
|
|
|
|
|
94
|
6 |
|
return $this; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Dump queries information |
|
99
|
|
|
* |
|
100
|
|
|
* @return mixed |
|
101
|
|
|
*/ |
|
102
|
6 |
|
public function dump() |
|
103
|
|
|
{ |
|
104
|
|
|
// |
|
105
|
6 |
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|