container = new Container(); } /** * Returns the singleton. */ public static function instance(): self { if ( null === self::$instance ) { self::$instance = new self(); } return self::$instance; } /** * Plugin version. */ public function version(): string { return EXTROVA_VERSION; } /** * Public hook contract version. */ public function api_version(): string { return EXTROVA_API_VERSION; } /** * Service container. */ public function container(): Container { return $this->container; } /** * Entry point on `plugins_loaded` (priority 10). */ public static function bootstrap(): void { $requirements = new Requirements(); if ( ! $requirements->met() ) { $requirements->register_notice(); return; } self::instance()->load(); } /** * Registers providers and schedules boot. */ private function load(): void { if ( $this->loaded ) { return; } $this->loaded = true; /** * Fires when the Lite is ready to register its services. Starting point for the Pro add-on. * * @since 1.0.0 * * @param Plugin $plugin Plugin instance. */ do_action( 'extrova_loaded', $this ); /** * Filters the service providers. Items may be ServiceProviderInterface instances or class names. * * @since 1.0.0 * * @param array $providers Providers. */ $providers = apply_filters( 'extrova_service_providers', $this->default_providers() ); foreach ( (array) $providers as $provider ) { if ( is_string( $provider ) && class_exists( $provider ) ) { $provider = new $provider(); } if ( $provider instanceof ServiceProviderInterface ) { $this->providers[] = $provider; } } foreach ( $this->providers as $provider ) { $provider->register( $this->container ); } add_action( 'init', array( $this, 'boot' ), 5 ); } /** * Boots providers on `init` priority 5. */ public function boot(): void { if ( $this->booted ) { return; } $this->booted = true; foreach ( $this->providers as $provider ) { $provider->boot( $this->container ); } /** * Fires once every provider is booted. * * @since 1.0.0 * * @param Container $container Service container. */ do_action( 'extrova_init', $this->container ); } /** * Lite providers, in order. * * @return ServiceProviderInterface[] */ private function default_providers(): array { return array( new Providers\CoreProvider(), new Providers\CartProvider(), new Providers\StoreApiProvider(), new Providers\BlocksProvider(), new Providers\ClassicProvider(), new Providers\OrderProvider(), new Providers\AdminProvider(), new Providers\CompatProvider(), ); } /** * Activation: creates the options with autoload disabled. No remote calls. */ public static function activate(): void { if ( false === get_option( OptionExtraRepository::OPTION, false ) ) { add_option( OptionExtraRepository::OPTION, Migrations::migrate_extras_data( array() ), '', false ); } if ( false === get_option( SettingsRepository::OPTION, false ) ) { add_option( SettingsRepository::OPTION, Schema::default_settings(), '', false ); } update_option( Migrations::VERSION_OPTION, EXTROVA_VERSION, false ); } }