<?php
/**
 * Auto loader for classes.
 *
 * @package Super_Advent_Calendar
 * @author  Verdant Studio
 * @since   1.0.0
 */

/**
 * Exit when accessed directly.
 */
if ( ! defined( 'ABSPATH' )) {
	exit;
}

$super_advent_calendar_classmap = array(
	'SuperAdventCalendar' => __DIR__ . '/',
);

spl_autoload_register(
	function (string $classname ) use ($super_advent_calendar_classmap ) {
		$parts = explode( '\\', $classname );

		$namespace = array_shift( $parts );
		$classfile = array_pop( $parts ) . '.php';

		if ( ! array_key_exists( $namespace, $super_advent_calendar_classmap )) {
			return;
		}

		$path = implode( DIRECTORY_SEPARATOR, $parts );
		$file = $super_advent_calendar_classmap[ $namespace ] . $path . DIRECTORY_SEPARATOR . $classfile;

		if ( ! file_exists( $file ) && ! class_exists( $classname )) {
			return;
		}

		require_once $file;
	}
);
