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