xref: /webtrees/app/Http/RequestHandlers/SelectTheme.php (revision a0801ffbb59d5bed474fc7a91bf1863ebca47791)
1*a0801ffbSGreg Roach<?php
2*a0801ffbSGreg Roach/**
3*a0801ffbSGreg Roach * webtrees: online genealogy
4*a0801ffbSGreg Roach * Copyright (C) 2019 webtrees development team
5*a0801ffbSGreg Roach * This program is free software: you can redistribute it and/or modify
6*a0801ffbSGreg Roach * it under the terms of the GNU General Public License as published by
7*a0801ffbSGreg Roach * the Free Software Foundation, either version 3 of the License, or
8*a0801ffbSGreg Roach * (at your option) any later version.
9*a0801ffbSGreg Roach * This program is distributed in the hope that it will be useful,
10*a0801ffbSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
11*a0801ffbSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12*a0801ffbSGreg Roach * GNU General Public License for more details.
13*a0801ffbSGreg Roach * You should have received a copy of the GNU General Public License
14*a0801ffbSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
15*a0801ffbSGreg Roach */
16*a0801ffbSGreg Roachdeclare(strict_types=1);
17*a0801ffbSGreg Roach
18*a0801ffbSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers;
19*a0801ffbSGreg Roach
20*a0801ffbSGreg Roachuse Fig\Http\Message\StatusCodeInterface;
21*a0801ffbSGreg Roachuse Fisharebest\Webtrees\Contracts\UserInterface;
22*a0801ffbSGreg Roachuse Fisharebest\Webtrees\Session;
23*a0801ffbSGreg Roachuse Psr\Http\Message\ResponseInterface;
24*a0801ffbSGreg Roachuse Psr\Http\Message\ServerRequestInterface;
25*a0801ffbSGreg Roachuse Psr\Http\Server\RequestHandlerInterface;
26*a0801ffbSGreg Roachuse function response;
27*a0801ffbSGreg Roach
28*a0801ffbSGreg Roach/**
29*a0801ffbSGreg Roach * Select a new theme for the current session.
30*a0801ffbSGreg Roach */
31*a0801ffbSGreg Roachclass SelectTheme implements RequestHandlerInterface, StatusCodeInterface
32*a0801ffbSGreg Roach{
33*a0801ffbSGreg Roach    /** @var UserInterface */
34*a0801ffbSGreg Roach    private $user;
35*a0801ffbSGreg Roach
36*a0801ffbSGreg Roach    /**
37*a0801ffbSGreg Roach     * @param UserInterface $user
38*a0801ffbSGreg Roach     */
39*a0801ffbSGreg Roach    public function __construct(UserInterface $user)
40*a0801ffbSGreg Roach    {
41*a0801ffbSGreg Roach        $this->user = $user;
42*a0801ffbSGreg Roach    }
43*a0801ffbSGreg Roach
44*a0801ffbSGreg Roach    /**
45*a0801ffbSGreg Roach     * @param ServerRequestInterface $request
46*a0801ffbSGreg Roach     *
47*a0801ffbSGreg Roach     * @return ResponseInterface
48*a0801ffbSGreg Roach     */
49*a0801ffbSGreg Roach    public function handle(ServerRequestInterface $request): ResponseInterface
50*a0801ffbSGreg Roach    {
51*a0801ffbSGreg Roach        $theme = $request->getParsedBody()['theme'];
52*a0801ffbSGreg Roach
53*a0801ffbSGreg Roach        Session::put('theme', $theme);
54*a0801ffbSGreg Roach
55*a0801ffbSGreg Roach        $this->user->setPreference('theme', $theme);
56*a0801ffbSGreg Roach
57*a0801ffbSGreg Roach        return response('', self::STATUS_NO_CONTENT);
58*a0801ffbSGreg Roach    }
59*a0801ffbSGreg Roach}
60