$version, 'bootstrap' => $bootstrap, ); } public static function register( array $descriptor ) { $product = isset( $descriptor['product_slug'] ) ? (string) $descriptor['product_slug'] : ''; if ( ! preg_match( '/^[a-z0-9][a-z0-9-]{1,63}$/', $product ) ) { return false; } self::$descriptors[ $product ] = $descriptor; if ( self::$booted ) { return self::boot_descriptor( $descriptor ); } self::schedule_boot(); return true; } public static function boot() { if ( self::$booted ) { return; } self::$booted = true; $candidate = self::best_candidate(); if ( null === $candidate ) { return; } if ( ! self::require_file( $candidate['bootstrap'] ) ) { return; } if ( ! class_exists( 'Signls\\Sdk\\V1\\Runtime' ) ) { return; } foreach ( self::$descriptors as $descriptor ) { self::boot_descriptor( $descriptor ); } } public static function selected_version() { $candidate = self::best_candidate(); return null === $candidate ? null : $candidate['version']; } private static function schedule_boot() { if ( self::$booted ) { return; } if ( function_exists( 'did_action' ) && did_action( 'plugins_loaded' ) ) { self::boot(); return; } if ( ! self::$hooked && function_exists( 'add_action' ) ) { self::$hooked = true; add_action( 'plugins_loaded', array( __CLASS__, 'boot' ), PHP_INT_MAX ); } } private static function best_candidate() { if ( empty( self::$candidates ) ) { return null; } $candidates = array_values( self::$candidates ); usort( $candidates, static function ( $left, $right ) { return version_compare( $right['version'], $left['version'] ); } ); return $candidates[0]; } private static function boot_descriptor( array $descriptor ) { try { $adapter_file = isset( $descriptor['adapter_file'] ) ? (string) $descriptor['adapter_file'] : ''; if ( '' !== $adapter_file && ! self::require_file( $adapter_file ) ) { return false; } return \Signls\Sdk\V1\Runtime::boot( $descriptor ); } catch ( \Throwable $error ) { // A product's observations must never break the host plugin. return false; } } private static function require_file( $path ) { if ( ! is_string( $path ) || ! is_file( $path ) ) { return false; } set_error_handler( // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_set_error_handler -- Contain a transient missing-file warning during plugin replacement. static function ( $severity, $message ) use ( $path ) { return E_WARNING === $severity && false !== strpos( $message, $path ); } ); try { require_once $path; return true; } catch ( \Throwable $error ) { return false; } finally { restore_error_handler(); } } } } require_once __DIR__ . '/bridge-1-1-5.php'; require_once __DIR__ . '/bridge-1-1-6.php'; require_once __DIR__ . '/bridge-1-1-7.php'; Signls_Sdk_Loader::add_candidate( '1.1.10', __DIR__ . '/sdk.php', '7.4.0' );