* @since 1.0.0 */ namespace AdPresso; if ( ! defined( 'ABSPATH' ) ) exit; /** * Autoloader. */ class Autoloader { /** * Hold autoloader. * * @var mixed */ private mixed $autoloader; /** * Main instance * * Ensure only one instance is loaded or can be loaded. * * @return Autoloader */ public static function get(): Autoloader { static $instance; if ( null === $instance ) { $instance = new Autoloader(); } return $instance; } /** * Private constructor to prevent direct instantiation. */ private function __construct() { } /** * Prevent cloning of the instance. */ private function __clone() { } /** * Get hold autoloader. * * @return mixed */ public function get_autoloader(): mixed { return $this->autoloader; } /** * Get the plugin directory. * * @return string */ public function get_directory(): string { return dirname( ADPRESSO_FILE ); } /** * Runs this initializer. * * @return void */ public function initialize(): void { $locate = $this->locate(); if ( ! $locate ) { add_action( 'admin_notices', [ $this, 'missing_autoloader' ] ); return; } $this->autoloader = require $locate; } /** * Locate the autoload file * * This function searches for the autoload file in the packages directory and vendor directory. * * @return bool|string */ private function locate(): bool|string { $directory = $this->get_directory(); $packages = $directory . '/packages/autoload.php'; $vendors = $directory . '/vendor/autoload.php'; $is_debug = $this->is_debug() || 'local' === $this->get_environment_type(); // If the vendor file is readable and we are in debug mode, prefer it. if ( $is_debug && is_readable( $vendors ) ) { return $vendors; } // Else use the packages file, if it is readable. if ( is_readable( $packages ) ) { return $packages; } // If the packages file is not readable, try the vendor file. if ( is_readable( $vendors ) ) { return $vendors; } return false; } /** * If the autoloader is missing, add an admin notice. * * @return void */ protected function missing_autoloader(): void { ?>

', '' ); ?>