<?php
namespace DebugBar\DataCollector;
use DebugBar\DataCollector\DataCollector;
use DebugBar\DataCollector\DataCollectorInterface;
use DebugBar\DataCollector\Renderable;
/**
* Collector for hit counts.
*/
class ObjectCountCollector extends DataCollector implements DataCollectorInterface, Renderable
{
/** @var string */
private $name;
/** @var string */
private $icon;
/** @var int */
protected $classCount = 0;
/** @var array */
protected $classList = [];
/**
* @param string $name
* @param string $icon
*/
public function __construct($name = 'counter', $icon = 'cubes')
{
$this->name = $name;
$this->icon = $icon;
}
/**
* @param string|mixed $class
* @param int $count
*/
public function countClass($class, $count = 1) {
if (! is_string($class)) {
$class = get_class($class);
}
$this->classList[$class] = ($this->classList[$class] ?? 0) + $count;
$this->classCount += $count;
}
/**
* {@inheritDoc}
*/
public function collect()
{
arsort($this->classList, SORT_NUMERIC);
if (! $this->getXdebugLinkTemplate()) {
return ['data' => $this->classList, 'count' => $this->classCount, 'is_counter' => true];
}
$data = [];
foreach ($this->classList as $class => $count) {
$reflector = class_exists($class) ? new \ReflectionClass($class) : null;
if ($reflector && $link = $this->getXdebugLink($reflector->getFileName())) {
$data[$class] = [
'value' => $count,
'xdebug_link' => $link,
];
} else {
$data[$class] = $count;
}
}
return ['data' => $data, 'count' => $this->classCount, 'is_counter' => true];
}
/**
* {@inheritDoc}
*/
public function getName()
{
return $this->name;
}
/**
* {@inheritDoc}
*/
public function getWidgets()
{
$name = $this->getName();
return [
"$name" => [
'icon' => $this->icon,
'widget' => 'PhpDebugBar.Widgets.HtmlVariableListWidget',
'map' => "$name.data",
'default' => '{}'
],
"$name:badge" => [
'map' => "$name.count",
'default' => 0
]
];
}
}
Contact Section
We’d love to hear from you! Whether you have questions, feedback, or need support, our team is here to help. Reach out to us via email, phone, or visit our office. We’re committed to providing you with exceptional service and ensuring your experience with NFC Pay is seamless and satisfying. Let’s connect!