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