Files
pr-vision/includes/core/class-pgm-collector-registry.php
peptiderepo 46fda89e18 peptide-geo-monitor v0.1.0: internal AI-visibility dashboard (#1)
New internal plugin: weekly LLM probes of core peptides (Perplexity sonar + GPT/Gemini-search via OpenRouter/CF gateway) -> custom table -> wp-admin trendline + standings. Provider interface + cost ledger w/ hard $5/mo cap + collector/panel seam (AI-visibility only). v1 = AI-visibility only.

QA: APPROVE-WITH-P2-NOTES — qa-reviews/peptide-geo-monitor/2026-06-13-f488f4a966cbb9e771d3abc20daee3fa49074520.md (P2 follow-ups: ltrim www display bug, PHPCS mandatory, dead cache)

Agent-Session: geomonitor v0.1.0 merge
2026-06-13 15:34:33 +07:00

113 lines
2.6 KiB
PHP

<?php
declare(strict_types=1);
/**
* Registry: holds all registered collectors and panels.
*
* PGM_Plugin::init() registers the v1 AI-visibility collector + panel.
* Future collectors/panels call register_collector()/register_panel()
* without touching the dashboard shell.
*
* Who triggers: PGM_Plugin::init() on plugins_loaded.
* Dependencies: PGM_Data_Collector, PGM_Dashboard_Panel interfaces.
*
* @see interface-pgm-data-collector.php — Collector contract.
* @see interface-pgm-dashboard-panel.php — Panel contract.
* @see class-pgm-plugin.php — Calls register_* on boot.
* @see ARCHITECTURE.md — §Collector/Panel seam.
* @package PeptideGeoMonitor
*/
class PGM_Collector_Registry {
/**
* Singleton instance.
*
* @var PGM_Collector_Registry|null
*/
private static ?PGM_Collector_Registry $instance = null;
/**
* Registered collectors keyed by their collector key.
*
* @var array<string, PGM_Data_Collector>
*/
private array $collectors = array();
/**
* Registered panels keyed by their panel key (matches collector key).
*
* @var array<string, PGM_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 PGM_Data_Collector $collector
*
* @return void
*/
public function register_collector( PGM_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 PGM_Dashboard_Panel $panel
*
* @return void
*/
public function register_panel( string $key, PGM_Dashboard_Panel $panel ): void {
$this->panels[ $key ] = $panel;
}
/**
* Get all registered collectors.
*
* @return array<string, PGM_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 PGM_Dashboard_Panel|null
*/
public function get_panel( string $key ): ?PGM_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;
}
}