All violations were present in v0.1.0 and hidden by continue-on-error. Now that PHPCS gates the build (P2-B), they must be fixed. - Add file-level @package doc comment to all PHP files (file doc requirement) - Add short descriptions to @var and constructor docblocks throughout - Fix @param type spacing throughout (PHPCS alignment rules) - Expand phpcs:ignore lines to include NoCaching where DirectQuery is already suppressed (uninstall.php, cost-ledger, table-manager, collector) - Suppress EscapeOutput.ExceptionNotEscaped on RuntimeException messages (exception strings are not HTML output) - Suppress error_log_error_log on the probe-runner failure log - Replace date() with gmdate() in panel (timezone-aware per WP standard) - Convert inline associative arrays to multi-line in config (WP array style) - Fix double-arrow alignment in probe-runner counts and insert arrays - Fix double-space before ?? in provider constructors - Expand phpcs:ignore for reads to include MissingUnslash - Fix $counts++ to ++$counts (prefix increment per WP standard) - Fix V1/v1 capitalisation in interface doc long description Agent-Session: pr-vision rename v0.1.1
114 lines
2.7 KiB
PHP
114 lines
2.7 KiB
PHP
<?php
|
|
/** @package PrVision */
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* Registry: holds all registered collectors and panels.
|
|
*
|
|
* PRV_Plugin::init() registers the v1 AI-visibility collector + panel.
|
|
* Future collectors/panels call register_collector()/register_panel()
|
|
* without touching the dashboard shell.
|
|
*
|
|
* Who triggers: PRV_Plugin::init() on plugins_loaded.
|
|
* Dependencies: PRV_Data_Collector, PRV_Dashboard_Panel interfaces.
|
|
*
|
|
* @see interface-prv-data-collector.php — Collector contract.
|
|
* @see interface-prv-dashboard-panel.php — Panel contract.
|
|
* @see class-prv-plugin.php — Calls register_* on boot.
|
|
* @see ARCHITECTURE.md — §Collector/Panel seam.
|
|
* @package PrVision
|
|
*/
|
|
class PRV_Collector_Registry {
|
|
|
|
/**
|
|
* Singleton instance.
|
|
*
|
|
* @var PRV_Collector_Registry|null
|
|
*/
|
|
private static ?PRV_Collector_Registry $instance = null;
|
|
|
|
/**
|
|
* Registered collectors keyed by their collector key.
|
|
*
|
|
* @var array<string, PRV_Data_Collector>
|
|
*/
|
|
private array $collectors = array();
|
|
|
|
/**
|
|
* Registered panels keyed by their panel key (matches collector key).
|
|
*
|
|
* @var array<string, PRV_Dashboard_Panel>
|
|
*/
|
|
private array $panels = array();
|
|
|
|
/**
|
|
* Private constructor — use instance().
|
|
*/
|
|
private function __construct() {}
|
|
|
|
/**
|
|
* Get (or create) the singleton instance.
|
|
*
|
|
* @return static
|
|
*/
|
|
public static function instance(): static {
|
|
if ( null === static::$instance ) {
|
|
static::$instance = new static();
|
|
}
|
|
return static::$instance;
|
|
}
|
|
|
|
/**
|
|
* Register a data collector.
|
|
*
|
|
* @param PRV_Data_Collector $collector The collector to register.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function register_collector( PRV_Data_Collector $collector ): void {
|
|
$this->collectors[ $collector->get_key() ] = $collector;
|
|
}
|
|
|
|
/**
|
|
* Register a dashboard panel.
|
|
*
|
|
* @param string $key Panel key (must match a collector key).
|
|
* @param PRV_Dashboard_Panel $panel The panel to register.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function register_panel( string $key, PRV_Dashboard_Panel $panel ): void {
|
|
$this->panels[ $key ] = $panel;
|
|
}
|
|
|
|
/**
|
|
* Get all registered collectors.
|
|
*
|
|
* @return array<string, PRV_Data_Collector>
|
|
*/
|
|
public function get_collectors(): array {
|
|
return $this->collectors;
|
|
}
|
|
|
|
/**
|
|
* Get the panel for a given key (null when not registered).
|
|
*
|
|
* @param string $key Panel key.
|
|
*
|
|
* @return PRV_Dashboard_Panel|null
|
|
*/
|
|
public function get_panel( string $key ): ?PRV_Dashboard_Panel {
|
|
return $this->panels[ $key ] ?? null;
|
|
}
|
|
|
|
/**
|
|
* Reset the registry — test use only.
|
|
*
|
|
* @internal
|
|
* @return void
|
|
*/
|
|
public static function reset_for_testing(): void {
|
|
static::$instance = null;
|
|
}
|
|
}
|