1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the Laravel Lodash package. |
4
|
|
|
* |
5
|
|
|
* (c) Avtandil Kikabidze aka LONGMAN <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
if (! function_exists('p')) { |
13
|
|
|
function p(...$values): void |
14
|
|
|
{ |
15
|
|
|
/** @var \Barryvdh\Debugbar\LaravelDebugbar $debugbar */ |
16
|
|
|
$debugbar = app('debugbar'); |
17
|
|
|
foreach ($values as $value) { |
18
|
|
|
$debugbar->addMessage($value, 'debug'); |
19
|
|
|
} |
20
|
|
|
} |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
if (! function_exists('get_db_query')) { |
24
|
|
|
function get_db_query(): ?string |
25
|
|
|
{ |
26
|
|
|
if (! app()->bound('debugbar')) { |
27
|
|
|
return null; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** @var \Barryvdh\Debugbar\LaravelDebugbar $debugbar */ |
31
|
|
|
$debugbar = app('debugbar'); |
32
|
|
|
|
33
|
|
|
try { |
34
|
|
|
$collector = $debugbar->getCollector('queries'); |
35
|
|
|
} catch (Exception $e) { |
36
|
|
|
return null; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
$queries = $collector->collect(); |
40
|
|
|
if (empty($queries['statements'])) { |
41
|
|
|
return null; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$query = end($queries['statements']); |
45
|
|
|
|
46
|
|
|
return $query['sql']; |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
if (! function_exists('get_db_queries')) { |
51
|
|
|
function get_db_queries(): ?array |
52
|
|
|
{ |
53
|
|
|
if (! app()->bound('debugbar')) { |
54
|
|
|
return null; |
55
|
|
|
} |
56
|
|
|
/** @var \Barryvdh\Debugbar\LaravelDebugbar $debugbar */ |
57
|
|
|
$debugbar = app('debugbar'); |
58
|
|
|
|
59
|
|
|
try { |
60
|
|
|
$collector = $debugbar->getCollector('queries'); |
61
|
|
|
} catch (Exception $e) { |
62
|
|
|
return null; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$queries = $collector->collect(); |
66
|
|
|
if (empty($queries['statements'])) { |
67
|
|
|
return null; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$list = []; |
71
|
|
|
foreach ($queries['statements'] as $query) { |
72
|
|
|
$list[] = $query['sql']; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return $list; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|