Skip to content

Commit d1a4896

Browse files
authored
Add files back for BC compact with 3rd party extensions (#1531)
1 parent 4b90deb commit d1a4896

File tree

2 files changed

+129
-0
lines changed

2 files changed

+129
-0
lines changed

src/DataCollector/JobsCollector.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace Barryvdh\Debugbar\DataCollector;
4+
5+
use DebugBar\DataCollector\DataCollector;
6+
use DebugBar\DataCollector\DataCollectorInterface;
7+
use DebugBar\DataCollector\Renderable;
8+
use Illuminate\Contracts\Events\Dispatcher;
9+
10+
/**
11+
* @deprecated in favor of \DebugBar\DataCollector\ObjectCountCollector
12+
*/
13+
class JobsCollector extends DataCollector implements DataCollectorInterface, Renderable
14+
{
15+
public $jobs = [];
16+
public $count = 0;
17+
18+
/**
19+
* @param Dispatcher $events
20+
*/
21+
public function __construct(Dispatcher $events)
22+
{
23+
$events->listen(\Illuminate\Queue\Events\JobQueued::class, function ($event) {
24+
$class = get_class($event->job);
25+
$this->jobs[$class] = ($this->jobs[$class] ?? 0) + 1;
26+
$this->count++;
27+
});
28+
}
29+
30+
public function collect()
31+
{
32+
ksort($this->jobs, SORT_NUMERIC);
33+
34+
return ['data' => array_reverse($this->jobs), 'count' => $this->count];
35+
}
36+
37+
/**
38+
* {@inheritDoc}
39+
*/
40+
public function getName()
41+
{
42+
return 'jobs';
43+
}
44+
45+
/**
46+
* {@inheritDoc}
47+
*/
48+
public function getWidgets()
49+
{
50+
return [
51+
"jobs" => [
52+
"icon" => "briefcase",
53+
"widget" => "PhpDebugBar.Widgets.HtmlVariableListWidget",
54+
"map" => "jobs.data",
55+
"default" => "{}"
56+
],
57+
'jobs:badge' => [
58+
'map' => 'jobs.count',
59+
'default' => 0
60+
]
61+
];
62+
}
63+
}

src/DataCollector/ModelsCollector.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
namespace Barryvdh\Debugbar\DataCollector;
4+
5+
use DebugBar\DataCollector\DataCollector;
6+
use DebugBar\DataCollector\DataCollectorInterface;
7+
use DebugBar\DataCollector\Renderable;
8+
use Illuminate\Contracts\Events\Dispatcher;
9+
10+
/**
11+
* Collector for Models.
12+
* @deprecated in favor of \DebugBar\DataCollector\ObjectCountCollector
13+
*/
14+
class ModelsCollector extends DataCollector implements DataCollectorInterface, Renderable
15+
{
16+
public $models = [];
17+
public $count = 0;
18+
19+
/**
20+
* @param Dispatcher $events
21+
*/
22+
public function __construct(Dispatcher $events)
23+
{
24+
$events->listen('eloquent.retrieved:*', function ($event, $models) {
25+
foreach (array_filter($models) as $model) {
26+
$class = get_class($model);
27+
$this->models[$class] = ($this->models[$class] ?? 0) + 1;
28+
$this->count++;
29+
}
30+
});
31+
}
32+
33+
public function collect()
34+
{
35+
ksort($this->models, SORT_NUMERIC);
36+
37+
return ['data' => array_reverse($this->models), 'count' => $this->count];
38+
}
39+
40+
/**
41+
* {@inheritDoc}
42+
*/
43+
public function getName()
44+
{
45+
return 'models';
46+
}
47+
48+
/**
49+
* {@inheritDoc}
50+
*/
51+
public function getWidgets()
52+
{
53+
return [
54+
"models" => [
55+
"icon" => "cubes",
56+
"widget" => "PhpDebugBar.Widgets.HtmlVariableListWidget",
57+
"map" => "models.data",
58+
"default" => "{}"
59+
],
60+
'models:badge' => [
61+
'map' => 'models.count',
62+
'default' => 0
63+
]
64+
];
65+
}
66+
}

0 commit comments

Comments
 (0)