. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Http\RequestHandlers; use Fisharebest\Webtrees\Contracts\UserInterface; use Fisharebest\Webtrees\Session; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; use function assert; use function is_string; use function response; /** * Select a new language for the current session. */ class SelectLanguage implements RequestHandlerInterface { /** * @param ServerRequestInterface $request * * @return ResponseInterface */ public function handle(ServerRequestInterface $request): ResponseInterface { $user = $request->getAttribute('user'); assert($user instanceof UserInterface); $language = $request->getAttribute('language'); assert(is_string($language)); Session::put('language', $language); $user->setPreference(UserInterface::PREF_LANGUAGE, $language); return response(); } }