<?php
/**
 * PVC Autoloader
 *
 * @package PageVisitCounter
 */

defined( 'ABSPATH' ) || exit;

/**
 * PVC Autoloader (PSR-like)
 */
spl_autoload_register(
	function ( $class ) {
		if ( strpos( $class, 'PageVICO\\' ) !== 0 ) {
			return;
		}

		$base_dir   = plugin_dir_path( __DIR__ ) . 'includes/';
		$class_path = str_replace( 'PageVICO\\', '', $class );
		$class_path = str_replace( '\\', DIRECTORY_SEPARATOR, $class_path );
		$file       = $base_dir . $class_path . '.php';

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