config = $config; $this->user = $user; $this->request = $request; $this->centralIdLookup = $centralIdLookup; } /** * @inheritDoc */ public function getName() : string { return Constants::REQUIREMENT_LANGUAGE_IN_HEADER; } /** * If A/B test is enabled check whether the user is logged in and bucketed. * Fallback to `VectorLanguageInHeader` config value. * * @inheritDoc * @throws \ConfigException */ public function isMet() : bool { if ( (bool)$this->config->get( Constants::CONFIG_LANGUAGE_IN_HEADER_TREATMENT_AB_TEST ) && $this->user->isRegistered() ) { if ( $this->request->getCheck( Constants::QUERY_PARAM_LANGUAGE_IN_HEADER ) ) { return $this->request->getBool( Constants::QUERY_PARAM_LANGUAGE_IN_HEADER ); } $id = null; if ( $this->centralIdLookup ) { $id = $this->centralIdLookup->centralIdFromLocalUser( $this->user ); } // $id will be 0 if the central ID lookup failed. if ( !$id ) { $id = $this->user->getId(); } return $id % 2 === 0; } // If AB test is not enabled, fallback to checking config state. $languageInHeaderConfig = $this->config->get( Constants::CONFIG_KEY_LANGUAGE_IN_HEADER ); // Backwards compatibility with config variables that have been set in production. if ( is_bool( $languageInHeaderConfig ) ) { $languageInHeaderConfig = [ 'logged_in' => $languageInHeaderConfig, 'logged_out' => $languageInHeaderConfig, ]; } else { $languageInHeaderConfig = [ 'logged_in' => $languageInHeaderConfig['logged_in'] ?? false, 'logged_out' => $languageInHeaderConfig['logged_out'] ?? false, ]; } return $languageInHeaderConfig[ $this->user->isRegistered() ? 'logged_in' : 'logged_out' ]; } }