*/ private array $types = []; private function __construct() { } /** * @return GroupTypeRegistry */ public static function get(): GroupTypeRegistry { if ( self::$instance === null ) { self::$instance = new self(); } return self::$instance; } /** * @param $type * * @return void */ public function register( $type ): void { $id = $type->get_id(); if ( isset( $this->types[ $id ] ) ) { RuntimeDebugger::add_doing_it_wrong_entry( sprintf( 'Group Type ID "%s" was overwritten. Origin type: %s, New type: %s', esc_html( $id ), esc_html( get_class( $this->types[ $id ] ) ), esc_html( get_class( $type ) ) ) ); } $this->types[ $id ] = $type; add_action( 'adpresso_group_types_registered', [ $type, 'register_fields' ], 10, 0 ); } /** * @param string $id * * @return Object|null */ public function get_by_id( string $id ): ?object { return $this->types[ $id ] ?? null; } }