xref: /webtrees/app/GuestUser.php (revision 81b729d3a9a6e0a0e8b96285d1ad7955d2d0c659)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2021 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 <https://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees;
21
22use Fisharebest\Webtrees\Contracts\UserInterface;
23
24/**
25 * A site visitor.
26 */
27class GuestUser implements UserInterface
28{
29    /**
30     * @var string
31     */
32    private $email;
33
34    /**
35     * @var string
36     */
37    private $real_name;
38
39    /**
40     * GuestUser constructor.
41     *
42     * @param string $email
43     * @param string $real_name
44     */
45    public function __construct(string $email = 'GUEST_USER', string $real_name = 'GUEST_USER')
46    {
47        $this->email = $email;
48        $this->real_name = $real_name;
49    }
50
51    /**
52     * The user‘s internal identifier.
53     *
54     * @return int
55     */
56    public function id(): int
57    {
58        return 0;
59    }
60
61    /**
62     * The users email address.
63     *
64     * @return string
65     */
66    public function email(): string
67    {
68        return $this->email;
69    }
70
71    /**
72     * The user‘s real name.
73     *
74     * @return string
75     */
76    public function realName(): string
77    {
78        return $this->real_name;
79    }
80
81    /**
82     * The user‘s login name.
83     *
84     * @return string
85     */
86    public function userName(): string
87    {
88        return '';
89    }
90
91    /**
92     * @param string $setting_name
93     * @param string $default
94     *
95     * @return string
96     */
97    public function getPreference(string $setting_name, string $default = ''): string
98    {
99        return Session::get('_GUEST_' . $setting_name, $default);
100    }
101
102    /**
103     * @param string $setting_name
104     * @param string $setting_value
105     *
106     * @return void
107     */
108    public function setPreference(string $setting_name, string $setting_value): void
109    {
110        Session::put('_GUEST_' . $setting_name, $setting_value);
111    }
112}
113