*/ private static array $shared = array(); /** * Register every component once. * * @return void */ public static function boot(): void { if ( isset( self::$shared['booted'] ) ) { return; } self::$shared['booted'] = new \stdClass(); self::translations()->register(); ( new Routing\Rewrites() )->register(); ( new Routing\Permalinks() )->register(); ( new Routing\QueryLanguage() )->register(); ( new Routing\StaticPages() )->register(); ( new Frontend\Locale() )->register(); ( new Frontend\Hreflang() )->register(); ( new Frontend\Switcher() )->register(); if ( is_admin() ) { ( new Admin\Settings() )->register(); ( new Admin\TranslationsBox() )->register(); } } /** * The language registry. * * @return Languages */ public static function languages(): Languages { $found = self::$shared['languages'] ?? null; if ( ! $found instanceof Languages ) { $found = new Languages(); self::$shared['languages'] = $found; } return $found; } /** * The translation storage. * * @return Translations */ public static function translations(): Translations { $found = self::$shared['translations'] ?? null; if ( ! $found instanceof Translations ) { $found = new Translations(); self::$shared['translations'] = $found; } return $found; } /** * The language addresses. * * @return Urls */ public static function urls(): Urls { $found = self::$shared['urls'] ?? null; if ( ! $found instanceof Urls ) { $found = new Urls(); self::$shared['urls'] = $found; } return $found; } /** * The request language. * * @return Request */ public static function request(): Request { $found = self::$shared['request'] ?? null; if ( ! $found instanceof Request ) { $found = new Request(); self::$shared['request'] = $found; } return $found; } /** * Activation: make the site's language the default and rebuild the routes on the next request. * * @return void */ public static function activate(): void { self::languages()->seed_from_site_locale(); delete_option( 'vabelon_rewrite_signature' ); } /** * Deactivation: let WordPress rebuild its rules without the language routes. * * @return void */ public static function deactivate(): void { delete_option( 'vabelon_rewrite_signature' ); delete_option( 'rewrite_rules' ); } }