<?php
/**
 * Lightweight autoloader.
 *
 * @package CertaCart_EU_Product_Readiness
 */

namespace CertaCart\EU_Product_Readiness;

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

spl_autoload_register(
	static function ( string $class ): void {
		$prefix = __NAMESPACE__ . '\\';
		if ( 0 !== strpos( $class, $prefix ) ) {
			return;
		}

		$relative = substr( $class, strlen( $prefix ) );
		$slug     = preg_replace( '/([a-z0-9])([A-Z])/', '$1-$2', $relative );
		$slug     = strtolower( preg_replace( '/-+/', '-', str_replace( array( '_', '\\' ), '-', (string) $slug ) ) );
		$file     = CCPR_PATH . 'includes/class-' . $slug . '.php';

		if ( is_readable( $file ) ) {
			require_once $file;
		}
	}
);
