Files
pr-vision/includes/core/class-pgm-collector-registry.php
peptiderepo ca1a41f6f9 feat: peptide-geo-monitor v0.1.0 — AI-visibility dashboard
Add initial plugin implementation per the CTO engineering handoff
(geomonitor/threads/2026-06-ai-visibility-v1/01-cto-eng-handoff.md).

## What
- PGM_Probe_Provider interface + PGM_Probe_Result value object
- PGM_Perplexity_Provider (sonar via OpenRouter/CF AI Gateway)
- PGM_OpenRouter_Provider (GPT-search + Gemini-search, generic parameterised)
- PGM_Gateway_Client: shared HTTP + exponential-backoff retry (mirrors PRAB)
- PGM_Citation_Detector: domain extraction, is_cited(), get_our_position()
- PGM_Cost_Ledger: MTD cost from DB, can_afford() pre-check, hard monthly cap
- PGM_Probe_Runner: peptides×intents×models run, budget abort, in-run cache
- PGM_Table_Manager: pgm_ai_visibility dbDelta, schema-version, drop_table()
- PGM_Config: typed getters, seed_defaults() (12 peptides, 3 intents, 3 models)
- PGM_Cron: weekly pgm_weekly_probe schedule/clear
- PGM_Data_Collector + PGM_Dashboard_Panel interfaces (seam for future panels)
- PGM_Collector_Registry: singleton registry
- PGM_Ai_Visibility_Collector: trendline, standings, MTD cost (score formula)
- PGM_Ai_Visibility_Panel: proxy note, Chart.js trendline, standings table
- PGM_Admin_Page: GEO Monitor menu, Run now POST handler (nonce+capability)
- uninstall.php: DROP TABLE + DELETE pgm_* options + wp_clear_scheduled_hook
- Unit tests (6 files): citation detection, score calc, cost ledger + budget
  abort, provider response parsing (mock HTTP), cron, uninstall purge
- ARCHITECTURE.md, CONVENTIONS.md, CONTEXT.md (score formula), README.md,
  CHANGELOG.md — same-commit per DoD
- CI workflow: PHP lint (8.1/8.2/8.3) + PHPCS + 300-line check

## Security
- Secrets from wp-config constants only; none hardcoded
- manage_options + nonce on every admin action
- Input sanitized; output escaped

Agent-Session: geomonitor v0.1.0
2026-06-13 08:18:56 +00: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;
}
}