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\FlareClient;
4
 
5
use Symfony\Component\VarDumper\Cloner\VarCloner;
6
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
7
 
8
class View
9
{
10
    protected string $file;
11
 
12
    /** @var array<string, mixed> */
13
    protected array $data = [];
14
 
15
    /**
16
     * @param string $file
17
     * @param array<string, mixed> $data
18
     */
19
    public function __construct(string $file, array $data = [])
20
    {
21
        $this->file = $file;
22
        $this->data = $data;
23
    }
24
 
25
    /**
26
     * @param string $file
27
     * @param array<string, mixed> $data
28
     *
29
     * @return self
30
     */
31
    public static function create(string $file, array $data = []): self
32
    {
33
        return new self($file, $data);
34
    }
35
 
36
    protected function dumpViewData(mixed $variable): string
37
    {
38
        $cloner = new VarCloner();
39
 
40
        $dumper = new HtmlDumper();
41
        $dumper->setDumpHeader('');
42
 
43
        $output = fopen('php://memory', 'r+b');
44
 
45
        if (! $output) {
46
            return '';
47
        }
48
 
49
        $dumper->dump($cloner->cloneVar($variable)->withMaxDepth(1), $output, [
50
            'maxDepth' => 1,
51
            'maxStringLength' => 160,
52
        ]);
53
 
54
        return (string)stream_get_contents($output, -1, 0);
55
    }
56
 
57
    /** @return array<string, mixed> */
58
    public function toArray(): array
59
    {
60
        return [
61
            'file' => $this->file,
62
            'data' => array_map([$this, 'dumpViewData'], $this->data),
63
        ];
64
    }
65
}