Skip to content

Commit

Permalink
Add badge to Model Collector
Browse files Browse the repository at this point in the history
  • Loading branch information
barryvdh authored Apr 16, 2020
1 parent aaf9274 commit 95c31aa
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/DataCollector/ModelsCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
class ModelsCollector extends DataCollector implements DataCollectorInterface, Renderable
{
public $models = [];
public $count = 0;

/**
* @param Dispatcher $events
Expand All @@ -25,6 +26,7 @@ public function __construct(Dispatcher $events)
foreach (array_filter($models) as $model) {
$class = get_class($model);
$this->models[$class] = ($this->models[$class] ?? 0) + 1;
$this->count++;
}
}
});
Expand All @@ -34,7 +36,7 @@ public function collect()
{
ksort($this->models, SORT_NUMERIC);

return array_reverse($this->models);
return ['data' => array_reverse($this->models), 'count' => $this->count];
}

/**
Expand All @@ -54,8 +56,12 @@ public function getWidgets()
"models" => [
"icon" => "cubes",
"widget" => "PhpDebugBar.Widgets.HtmlVariableListWidget",
"map" => "models",
"map" => "models.data",
"default" => "{}"
],
'models:badge' => [
'map' => 'models.count',
'default' => 0
]
];
}
Expand Down

0 comments on commit 95c31aa

Please sign in to comment.