diff --git a/bavarian-rank-engine/includes/Providers/ProviderRegistry.php b/bavarian-rank-engine/includes/Providers/ProviderRegistry.php new file mode 100644 index 0000000..a06d95c --- /dev/null +++ b/bavarian-rank-engine/includes/Providers/ProviderRegistry.php @@ -0,0 +1,45 @@ +providers[ $provider->getId() ] = $provider; + } + + public function get( string $id ): ?ProviderInterface { + return $this->providers[ $id ] ?? null; + } + + /** @return ProviderInterface[] */ + public function all(): array { + return $this->providers; + } + + /** Reset singleton — for use in tests only */ + public static function reset(): void { + self::$instance = null; + } + + /** Returns ['id' => 'Name'] for dropdowns */ + public function getSelectOptions(): array { + $options = array(); + foreach ( $this->providers as $id => $provider ) { + $options[ $id ] = $provider->getName(); + } + return $options; + } +}