<?php
/**
 * PSR-4 Autoloader.
 *
 * Maps the `Platform\Helm\` namespace to the `src/` directory. Deliberately
 * dependency-free (no Composer required) so the plugin drops onto any host.
 *
 * @package Platform\Helm
 */

declare( strict_types = 1 );

namespace Platform\Helm;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

final class Autoloader {

	private const NAMESPACE_PREFIX   = 'Platform\\Helm\\';
	private const BASE_DIR_RELATIVE  = 'src/';

	public static function register(): void {
		spl_autoload_register( [ self::class, 'load' ] );
	}

	public static function load( string $fqcn ): void {
		if ( 0 !== strpos( $fqcn, self::NAMESPACE_PREFIX ) ) {
			return;
		}
		$relative = substr( $fqcn, strlen( self::NAMESPACE_PREFIX ) );
		$path     = PLATFORM_HELM_DIR
			. self::BASE_DIR_RELATIVE
			. str_replace( '\\', DIRECTORY_SEPARATOR, $relative )
			. '.php';
		if ( is_readable( $path ) ) {
			require_once $path;
		}
	}
}
