base_dir = ACUMENPOPUP_PLUGIN_DIR . 'includes/'; $this->register(); } /** * Get the single instance of the Autoloader. * * @since 1.0.0 * @access public * * @return Autoloader The single instance. */ public static function get_instance() { if ( is_null( self::$instance ) ) { self::$instance = new self(); } return self::$instance; } /** * Register the autoloader with SPL. * * @since 1.0.0 * @access private * * @return void */ private function register() { spl_autoload_register( array( $this, 'autoload' ) ); } /** * Add a class to the class map. * * @since 1.0.0 * @access public * * @param string $class The fully qualified class name. * @param string $filepath The file path for the class. * * @return void */ public function add_class_map( $class, $filepath ) { $this->class_map[ $class ] = $filepath; } /** * Autoload callback function. * * Called by SPL autoloader when a class needs to be loaded. * * @since 1.0.0 * @access public * * @param string $class The fully qualified class name. * * @return void */ public function autoload( $class ) { // Check if the class is in our namespace. if ( 0 !== strpos( $class, $this->namespace . '\\' ) ) { return; } // Check class map first. if ( isset( $this->class_map[ $class ] ) ) { $file = $this->class_map[ $class ]; if ( file_exists( $file ) ) { require_once $file; return; } } // Remove the base namespace from the class name. $relative_class = substr( $class, strlen( $this->namespace . '\\' ) ); // Convert namespace separators to directory separators. $relative_path = str_replace( '\\', '/', $relative_class ); // Convert class name format (e.g., Dynamic_Style -> Dynamic_Style). $file = $this->base_dir . $relative_path . '.php'; // Load the file if it exists. if ( file_exists( $file ) ) { require_once $file; } } /** * Prevent cloning of the instance. * * @since 1.0.0 * @access public * * @return void */ public function __clone() { _doing_it_wrong( __FUNCTION__, esc_html__( 'Cloning is forbidden.', 'acumen-popup' ), '1.0.0' ); } /** * Prevent unserializing of the instance. * * @since 1.0.0 * @access public * * @return void */ public function __wakeup() { _doing_it_wrong( __FUNCTION__, esc_html__( 'Unserializing is forbidden.', 'acumen-popup' ), '1.0.0' ); } }