Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Spatie\LaravelIgnition\Recorders\QueryRecorder;
4
 
5
use Illuminate\Database\Events\QueryExecuted;
6
 
7
class Query
8
{
9
    protected string $sql;
10
 
11
    protected float $time;
12
 
13
    protected string $connectionName;
14
 
15
    /** @var array<string, string>|null */
16
    protected ?array $bindings;
17
 
18
    protected float $microtime;
19
 
20
    public static function fromQueryExecutedEvent(QueryExecuted $queryExecuted, bool $reportBindings = false): self
21
    {
22
        return new self(
23
            $queryExecuted->sql,
24
            $queryExecuted->time,
25
            /** @phpstan-ignore-next-line  */
26
            $queryExecuted->connectionName ?? '',
27
            $reportBindings ? $queryExecuted->bindings : null
28
        );
29
    }
30
 
31
    /**
32
     * @param string $sql
33
     * @param float $time
34
     * @param string $connectionName
35
     * @param array<string, string>|null $bindings
36
     * @param float|null $microtime
37
     */
38
    protected function __construct(
39
        string $sql,
40
        float $time,
41
        string $connectionName,
42
        ?array $bindings = null,
43
        ?float $microtime = null
44
    ) {
45
        $this->sql = $sql;
46
        $this->time = $time;
47
        $this->connectionName = $connectionName;
48
        $this->bindings = $bindings;
49
        $this->microtime = $microtime ?? microtime(true);
50
    }
51
 
52
    /**
53
     * @return array<string, mixed>
54
     */
55
    public function toArray(): array
56
    {
57
        return [
58
            'sql' => $this->sql,
59
            'time' => $this->time,
60
            'connection_name' => $this->connectionName,
61
            'bindings' => $this->bindings,
62
            'microtime' => $this->microtime,
63
        ];
64
    }
65
}