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