profile = $profile; $this->license_provider = $license_provider; $this->feature_registry = $feature_registry; $this->module_loader = $module_loader instanceof ProModuleLoader ? $module_loader : $this->create_module_loader( $profile, $feature_registry, $license_provider ); } /** * Create default bootstrap boundary. * * @param BuildProfileResolver|null $resolver Profile resolver. */ public static function create_default( ?BuildProfileResolver $resolver = null ): self { $resolver = $resolver instanceof BuildProfileResolver ? $resolver : new BuildProfileResolver(); $profile = $resolver->resolve(); $provider = self::create_provider_for_profile( $profile ); $status = $provider->get_status( $profile ); return new self( $profile, $provider, new FeatureRegistry( $profile, $status ) ); } /** * Boot future commercial modules when the profile allows it. */ public function boot(): void { if ( $this->module_loader instanceof ProModuleLoader ) { $this->module_loader->boot(); } } /** * Get build profile. */ public function get_profile(): BuildProfile { return $this->profile; } /** * Get feature registry. */ public function get_feature_registry(): FeatureRegistry { return $this->feature_registry; } /** * Get license provider. */ public function get_license_provider(): LicenseProviderInterface { return $this->license_provider; } /** * Get loaded module count. */ public function get_loaded_module_count(): int { return $this->module_loader instanceof ProModuleLoader ? $this->module_loader->get_loaded_module_count() : 0; } /** * Get safe PRO module skeleton metadata. * * @return array */ public function get_pro_module_metadata(): array { return $this->module_loader instanceof ProModuleLoader ? $this->module_loader->get_module_metadata() : array(); } /** * Create the optional PRO module loader only when the profile can use it. * * @param BuildProfile $profile Build profile. * @param FeatureRegistry $feature_registry Feature registry. * @param LicenseProviderInterface $license_provider License provider. */ private function create_module_loader( BuildProfile $profile, FeatureRegistry $feature_registry, LicenseProviderInterface $license_provider ): ?ProModuleLoader { if ( ! $profile->allows_commercial_boundary() ) { return null; } if ( ! class_exists( ProModuleLoader::class ) ) { return null; } return new ProModuleLoader( $profile, $feature_registry, $license_provider ); } /** * Create the inert provider for a profile. * * @param BuildProfile $profile Build profile. */ private static function create_provider_for_profile( BuildProfile $profile ): LicenseProviderInterface { if ( BuildProfile::PRO_FREEMIUS === $profile->get_value() && class_exists( FreemiusLicenseProvider::class ) ) { return new FreemiusLicenseProvider(); } if ( BuildProfile::PRO_CODECANYON === $profile->get_value() && class_exists( EnvatoLicenseProvider::class ) ) { return new EnvatoLicenseProvider(); } return new NullLicenseProvider(); } }