<?php
namespace Atlasly\Core;

class Autoloader {

    public static function register() {
        spl_autoload_register( [ __CLASS__, 'autoload' ] );
    }

    private static function autoload( $class ) {

        // Only load Atlasly classes
        if ( strpos( $class, 'Atlasly\\' ) !== 0 ) {
            return;
        }

        // Convert namespace to file path
        $path = str_replace(
            [ 'Atlasly\\', '\\' ],
            [ '', DIRECTORY_SEPARATOR ],
            $class
        );

        $file = ATLASLY_PATH . 'includes/' . $path . '.php';

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