aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/Debug/TrailsCollector.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/classes/Debug/TrailsCollector.php')
-rw-r--r--lib/classes/Debug/TrailsCollector.php69
1 files changed, 69 insertions, 0 deletions
diff --git a/lib/classes/Debug/TrailsCollector.php b/lib/classes/Debug/TrailsCollector.php
new file mode 100644
index 0000000..f4b8a65
--- /dev/null
+++ b/lib/classes/Debug/TrailsCollector.php
@@ -0,0 +1,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()),
+ ],
+ ];
+ }
+}