Skip to content

Commit

Permalink
Add files back for BC compact with 3rd party extensions (#1531)
Browse files Browse the repository at this point in the history
  • Loading branch information
barryvdh authored Feb 15, 2024
1 parent 4b90deb commit d1a4896
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/DataCollector/JobsCollector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace Barryvdh\Debugbar\DataCollector;

use DebugBar\DataCollector\DataCollector;
use DebugBar\DataCollector\DataCollectorInterface;
use DebugBar\DataCollector\Renderable;
use Illuminate\Contracts\Events\Dispatcher;

/**
* @deprecated in favor of \DebugBar\DataCollector\ObjectCountCollector
*/
class JobsCollector extends DataCollector implements DataCollectorInterface, Renderable
{
public $jobs = [];
public $count = 0;

/**
* @param Dispatcher $events
*/
public function __construct(Dispatcher $events)
{
$events->listen(\Illuminate\Queue\Events\JobQueued::class, function ($event) {
$class = get_class($event->job);
$this->jobs[$class] = ($this->jobs[$class] ?? 0) + 1;
$this->count++;
});
}

public function collect()
{
ksort($this->jobs, SORT_NUMERIC);

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

/**
* {@inheritDoc}
*/
public function getName()
{
return 'jobs';
}

/**
* {@inheritDoc}
*/
public function getWidgets()
{
return [
"jobs" => [
"icon" => "briefcase",
"widget" => "PhpDebugBar.Widgets.HtmlVariableListWidget",
"map" => "jobs.data",
"default" => "{}"
],
'jobs:badge' => [
'map' => 'jobs.count',
'default' => 0
]
];
}
}
66 changes: 66 additions & 0 deletions src/DataCollector/ModelsCollector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace Barryvdh\Debugbar\DataCollector;

use DebugBar\DataCollector\DataCollector;
use DebugBar\DataCollector\DataCollectorInterface;
use DebugBar\DataCollector\Renderable;
use Illuminate\Contracts\Events\Dispatcher;

/**
* Collector for Models.
* @deprecated in favor of \DebugBar\DataCollector\ObjectCountCollector
*/
class ModelsCollector extends DataCollector implements DataCollectorInterface, Renderable
{
public $models = [];
public $count = 0;

/**
* @param Dispatcher $events
*/
public function __construct(Dispatcher $events)
{
$events->listen('eloquent.retrieved:*', function ($event, $models) {
foreach (array_filter($models) as $model) {
$class = get_class($model);
$this->models[$class] = ($this->models[$class] ?? 0) + 1;
$this->count++;
}
});
}

public function collect()
{
ksort($this->models, SORT_NUMERIC);

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

/**
* {@inheritDoc}
*/
public function getName()
{
return 'models';
}

/**
* {@inheritDoc}
*/
public function getWidgets()
{
return [
"models" => [
"icon" => "cubes",
"widget" => "PhpDebugBar.Widgets.HtmlVariableListWidget",
"map" => "models.data",
"default" => "{}"
],
'models:badge' => [
'map' => 'models.count',
'default' => 0
]
];
}
}

0 comments on commit d1a4896

Please sign in to comment.