. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Http\RequestHandlers; use Fig\Http\Message\StatusCodeInterface; 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 response; /** * Select a new language for the current session. */ class SelectLanguage implements RequestHandlerInterface, StatusCodeInterface { /** @var UserInterface */ private $user; /** * @param UserInterface $user */ public function __construct(UserInterface $user) { $this->user = $user; } /** * @param ServerRequestInterface $request * * @return ResponseInterface */ public function handle(ServerRequestInterface $request): ResponseInterface { $language = $request->getParsedBody()['language']; Session::put('language', $language); $this->user->setPreference('language', $language); return response('', StatusCodeInterface::STATUS_NO_CONTENT); } }