xref: /webtrees/app/GuestUser.php (revision 3d0d3c4eac0d9885ecf85cce0ac6e76860c614d4)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2019 webtrees development team
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16declare(strict_types=1);
17
18namespace Fisharebest\Webtrees;
19
20use Fisharebest\Webtrees\Contracts\UserInterface;
21
22/**
23 * A site visitor.
24 */
25class GuestUser implements UserInterface
26{
27    /**
28     * @var string
29     */
30    private $email;
31
32    /**
33     * @var string
34     */
35    private $real_name;
36
37    /**
38     * GuestUser constructor.
39     *
40     * @param string $email
41     * @param string $real_name
42     */
43    public function __construct(string $email = 'GUEST_USER', string $real_name = 'GUEST_USER')
44    {
45        $this->email = $email;
46        $this->real_name = $real_name;
47    }
48
49    /**
50     * The user‘s internal identifier.
51     *
52     * @return int
53     */
54    public function id(): int
55    {
56        return 0;
57    }
58
59    /**
60     * The users email address.
61     *
62     * @return string
63     */
64    public function email(): string
65    {
66        return $this->email;
67    }
68
69    /**
70     * The user‘s real name.
71     *
72     * @return string
73     */
74    public function realName(): string
75    {
76        return $this->real_name;
77    }
78
79    /**
80     * The user‘s login name.
81     *
82     * @return string
83     */
84    public function userName(): string
85    {
86        return '';
87    }
88
89    /**
90     * @param string $setting_name
91     * @param string $default
92     *
93     * @return string
94     */
95    public function getPreference(string $setting_name, string $default = ''): string
96    {
97        return Session::get('_GUEST_' . $setting_name, $default);
98    }
99
100    /**
101     * @param string $setting_name
102     * @param string $setting_value
103     *
104     * @return UserInterface
105     */
106    public function setPreference(string $setting_name, string $setting_value): UserInterface
107    {
108        Session::put('_GUEST_' . $setting_name, $setting_value);
109
110        return $this;
111    }
112}
113