. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Http\RequestHandlers; use Fisharebest\Webtrees\Contracts\UserInterface; use Fisharebest\Webtrees\Session; use InvalidArgumentException; 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, new InvalidArgumentException()); $language = $request->getAttribute('language'); assert(is_string($language), new InvalidArgumentException()); Session::put('language', $language); $user->setPreference('language', $language); return response(); } }