mirror of
https://github.com/NamelessMC/Nameless
synced 2026-08-18 06:29:04 -04:00
* Create StyleCI config file * Disable `phpdoc_separation` * Apply fixes from StyleCI (#3476) Co-authored-by: StyleCI Bot <bot@styleci.io> * style: styleci fixes --------- Co-authored-by: StyleCI Bot <bot@styleci.io> Co-authored-by: Sam <samerton@users.noreply.github.com>
76 lines
1.7 KiB
PHP
76 lines
1.7 KiB
PHP
<?php
|
|
|
|
use DebugBar\DataCollector\AssetProvider;
|
|
use DebugBar\DataCollector\DataCollector;
|
|
use DebugBar\DataCollector\Renderable;
|
|
|
|
/**
|
|
* Interacts with the DebugBar to display executed events.
|
|
*
|
|
* @see DebugBarHelper
|
|
* @package NamelessMC\Events
|
|
* @author Aberdeener
|
|
* @version 2.2.0
|
|
* @license MIT
|
|
*/
|
|
class EventCollector extends DataCollector implements Renderable, AssetProvider
|
|
{
|
|
private array $_events = [];
|
|
private static EventCollector $_instance;
|
|
|
|
public static function getInstance(): EventCollector
|
|
{
|
|
return self::$_instance ??= new self();
|
|
}
|
|
|
|
public function called(string $event, array $params): void
|
|
{
|
|
$this->_events[] = [
|
|
'event' => $event,
|
|
'params' => $params,
|
|
];
|
|
}
|
|
|
|
public function collect(): array
|
|
{
|
|
$events = [];
|
|
|
|
foreach ($this->_events as $i => $event) {
|
|
$i++;
|
|
$events["{$event['event']} #$i"] = [
|
|
$this->getVarDumper()->renderVar($event['params']),
|
|
];
|
|
}
|
|
|
|
return [
|
|
'count' => count($events),
|
|
'vars' => $events,
|
|
];
|
|
}
|
|
|
|
public function getName(): string
|
|
{
|
|
return 'events';
|
|
}
|
|
|
|
public function getAssets(): array
|
|
{
|
|
return $this->getVarDumper()->getAssets();
|
|
}
|
|
|
|
public function getWidgets(): array
|
|
{
|
|
return [
|
|
'events' => [
|
|
'icon' => 'tags',
|
|
'widget' => 'PhpDebugBar.Widgets.HtmlVariableListWidget',
|
|
'map' => 'events.vars',
|
|
'default' => '{}',
|
|
],
|
|
'events:badge' => [
|
|
'map' => 'events.count',
|
|
'default' => 0,
|
|
],
|
|
];
|
|
}
|
|
}
|