setup(); self::$instances[] = $instance; } public static function get_instances() { return self::$instances; } /** * @template T * @param class-string $class_name * @return T|null */ public static function get_instance_of( $class_name ) { foreach ( self::get_instances() as $instance ) { if ( $instance instanceof $class_name ) { // @phan-suppress-next-line PhanTypeMismatchReturn -- Phan isn't inferring the type correctly from the `instanceof $class_name` like it's supposed to. return $instance; } } return null; } }