*/ private $modules = array(); /** * Get singleton. * * @return self */ public static function instance() { if ( null === self::$instance ) { self::$instance = new self(); } return self::$instance; } /** * Constructor. */ private function __construct() { $this->settings = new Settings(); $this->logger = new Logger( $this->settings ); $this->filesystem = new Filesystem( $this->logger ); } /** * Boot plugin. * * @return void */ public function run() { $this->filesystem->prepare(); $this->register_modules(); foreach ( $this->modules as $module ) { if ( method_exists( $module, 'register' ) ) { $module->register(); } } ( new Cron( $this ) )->register(); ( new Ajax( $this ) )->register(); ( new Admin( $this ) )->register(); } /** * Register module instances. * * @return void */ private function register_modules() { $this->modules = array( 'page_cache' => new Page_Cache( $this->settings, $this->logger, $this->filesystem ), 'preloader' => new Preloader( $this->settings, $this->logger ), 'browser' => new Browser_Cache( $this->settings, $this->logger ), 'css' => new CSS_Optimizer( $this->settings ), 'js' => new JS_Optimizer( $this->settings ), 'images' => new Image_Optimizer( $this->settings, $this->logger ), 'database' => new Database_Optimizer( $this->settings, $this->logger ), 'heartbeat' => new Heartbeat_Manager( $this->settings ), 'compression' => new Compression_Engine( $this->settings ), 'lazy' => new Lazy_Loading( $this->settings ), 'cdn' => new CDN( $this->settings ), 'analytics' => new Analytics( $this->settings, $this->logger, $this->filesystem ), ); } /** * Get a module. * * @param string $key Module key. * @return object|null */ public function module( $key ) { return isset( $this->modules[ $key ] ) ? $this->modules[ $key ] : null; } /** * Purge all caches managed by this plugin. * * @return int Deleted file count. */ public function purge_all_caches() { $deleted = 0; $cache = $this->module( 'page_cache' ); if ( $cache && method_exists( $cache, 'purge_all' ) ) { $deleted += absint( $cache->purge_all() ); } $deleted += absint( $this->filesystem->clear_directory( $this->filesystem->asset_cache_dir() ) ); /** * Fires after Acelora clears plugin-managed caches. * * @param int $deleted Deleted file count. */ do_action( 'acelora_site_accelerator_cache_purged', $deleted ); return $deleted; } /** * Get settings service. * * @return Settings */ public function settings() { return $this->settings; } /** * Get logger service. * * @return Logger */ public function logger() { return $this->logger; } /** * Get filesystem service. * * @return Filesystem */ public function filesystem() { return $this->filesystem; } }