aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/Debug/TrailsCollector.php
blob: f4b8a65073ad15b4f207470ea740e237a9a723ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace Studip\Debug;

use DebugBar\DataCollector\DataCollector;
use DebugBar\DataCollector\Renderable;
use Trails\Controller;

final class TrailsCollector extends DataCollector implements Renderable
{
    public function __construct(
        private readonly Controller $controller
    ) {
        $this->useHtmlVarDumper(false);
    }

    public function collect()
    {
        $data = [];
        foreach ($this->controller->get_assigned_variables() as $k => $v) {
            if ($this->isHtmlVarDumperUsed()) {
                $v = $this->getVarDumper()->renderVar($v);
            } else if (!is_string($v)) {
                $v = $this->getDataFormatter()->formatVar($v);
            }
            $data[$k] = $v;
        }

        ksort($data);

        return $data;
    }

    public function getName()
    {
        return 'trails';
    }

    /**
     * @return array
     */
    public function getAssets()
    {
        return $this->isHtmlVarDumperUsed() ? $this->getVarDumper()->getAssets() : [];
    }

    /**
     * @return array[]
     */
    public function getWidgets()
    {
        $name = $this->getName();
        $widget = $this->isHtmlVarDumperUsed()
            ? 'PhpDebugBar.Widgets.HtmlVariableListWidget'
            : 'PhpDebugBar.Widgets.VariableListWidget';

        return [
            $name => [
                'icon'   => 'code',
                'widget' => $widget,
                'map' => $name,
                'default' => '{}'
            ],
            "{$name}:badge" => [
                'map' => "{$name}:variable__count",
                'default' => count($this->controller->get_assigned_variables()),
            ],
        ];
    }
}