# blocks/trunk/includes/signls/loader.php

Blocks – Reusable Content, Shortcodes &amp; Site Variables, version trunk. 150 lines.

- Page: https://pluginprobe.com/plugins/blocks/trunk/code/includes/signls/loader.php
- Raw: https://pluginprobe.com/plugins/blocks/trunk/raw/includes/signls/loader.php
- Modified: 2026-09-03T18:44:58+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/blocks/trunk/code/includes/signls/loader.php#L10-L20`.

```php
<?php
/**
 * Collision-safe loader for vendored Signls SDK copies.
 *
 * @package signls-sdk
 * @license GPL-3.0-or-later
 */

defined( 'ABSPATH' ) || exit;

if ( ! class_exists( 'Signls_Sdk_Loader', false ) ) {
	final class Signls_Sdk_Loader {

		private static $candidates = array();

		private static $descriptors = array();

		private static $booted = false;

		private static $hooked = false;

		public static function add_candidate( $version, $bootstrap, $minimum_php = '7.4.0' ) {
			if ( ! is_string( $version ) || ! is_string( $bootstrap ) || ! is_string( $minimum_php ) ) {
				return;
			}

			if ( ! is_file( $bootstrap ) || version_compare( PHP_VERSION, $minimum_php, '<' ) ) {
				return;
			}

			self::$candidates[ $version . '|' . $bootstrap ] = array(
				'version'   => $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' );

```
