<?php
/**
 * Internal autoloader.
 *
 * @package VoidPulse
 */

namespace VoidPulse\Core;

defined( 'ABSPATH' ) || exit;

final class Autoloader {
	/**
	 * Register the loader.
	 *
	 * @return void
	 */
	public static function register() {
		spl_autoload_register( array( __CLASS__, 'load' ) );
	}

	/**
	 * Load a VoidPulse class.
	 *
	 * @param string $class Fully-qualified class name.
	 * @return void
	 */
	public static function load( $class ) {
		$prefix = 'VoidPulse\\';
		if ( 0 !== strpos( $class, $prefix ) ) {
			return;
		}

		$relative = str_replace( '\\', '/', substr( $class, strlen( $prefix ) ) );
		if ( false !== strpos( $relative, '..' ) ) {
			return;
		}

		$file = VOIDPULSE_PATH . 'includes/' . $relative . '.php';
		if ( is_readable( $file ) ) {
			require_once $file;
		}
	}
}
