container ) ) { return $this->container[ $key ]; } return null; } /** * Get environment * * @return string */ public function environment() { $environment = 'production'; if ( $this->isStagingModeDefined() || $this->isStagingFileExists() ) { $environment = 'development'; } return $environment; } /** * Check CL_STAGING_MODE constant. * * @return bool */ public function isStagingModeDefined() { return ( defined( 'CL_STAGING_MODE' ) && CL_STAGING_MODE ); } /** * Check staging file. * * @return bool */ public function isStagingFileExists() { return @file_exists( '/opt/cloudlinux/staging_mode' ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged } /** * Setup container. * * @return void */ private function coreSetup() { $this->container[ Debug::class ] = new Debug( $this->environment() ); $this->container[ Api::class ] = new ApiSocket(); $this->container[ Option::class ] = new Option(); $this->container[ Update::class ] = new Update( $this->get( Option::class ) ); $this->get( Update::class )->update(); $this->container[ Analytics::class ] = new Analytics( $this->environment() ); $this->container[ NoticeManager::class ] = new NoticeManager( $this->get( Option::class ) ); $this->container[ AdviceManager::class ] = new AdviceManager( $this->get( Api::class ), $this->get( Option::class ) ); $this->container[ SubscriptionManager::class ] = new SubscriptionManager( $this->get( Option::class ), $this->get( AdviceManager::class ), $this->get( Analytics::class ) ); $this->container[ MailService::class ] = new MailService( $this->get( AdviceManager::class )->domain(), $this->get( AdviceManager::class )->home(), $this->get( Option::class ), $this->get( Analytics::class ) ); add_action( 'shutdown', array( $this, 'shutdown' ) ); add_action( 'cl_smart_advice_uninstall', array( $this, 'shutdown' ) ); } /** * Additional setup for WP Admin env. * * @return void */ private function adminSetup() { $this->container[ Admin::class ] = new Admin( $this->get( Analytics::class ), $this->get( Debug::class ) ); $this->container[ Widget::class ] = new Widget( $this->get( AdviceManager::class ) ); $this->container[ Settings::class ] = new Settings( $this->get( AdviceManager::class ), $this->get( NoticeManager::class ) ); } /** * Init plugin. * * @return void */ public function init() { $this->coreSetup(); if ( is_admin() ) { $this->adminSetup(); } } /** * Auto delete. * * @param bool $do_uninstall Delete plugin symlink. * * @return void */ public function shutdown( $do_uninstall = false ) { if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { return; } /* @var AdviceManager $manager advices. */ $manager = $this->get( AdviceManager::class ); $sync_failed = apply_filters( 'cl_smart_advice_sync_failed', false ); if ( ( empty( $manager->syncAt() ) && $sync_failed ) || ( ! empty( $manager->syncAt() ) && empty( $manager->advices() ) && ! $sync_failed ) || true === $do_uninstall ) { do_action( 'cl_smart_advice_deleting' ); } } }