1<?php 2 3/** 4 * webtrees: online genealogy 5 * Copyright (C) 2022 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 private string $email; 30 31 private string $real_name; 32 33 /** 34 * GuestUser constructor. 35 * 36 * @param string $email 37 * @param string $real_name 38 */ 39 public function __construct(string $email = 'GUEST_USER', string $real_name = 'GUEST_USER') 40 { 41 $this->email = $email; 42 $this->real_name = $real_name; 43 } 44 45 /** 46 * The user‘s internal identifier. 47 * 48 * @return int 49 */ 50 public function id(): int 51 { 52 return 0; 53 } 54 55 /** 56 * The users email address. 57 * 58 * @return string 59 */ 60 public function email(): string 61 { 62 return $this->email; 63 } 64 65 /** 66 * The user‘s real name. 67 * 68 * @return string 69 */ 70 public function realName(): string 71 { 72 return $this->real_name; 73 } 74 75 /** 76 * The user‘s login name. 77 * 78 * @return string 79 */ 80 public function userName(): string 81 { 82 return ''; 83 } 84 85 /** 86 * @param string $setting_name 87 * @param string $default 88 * 89 * @return string 90 */ 91 public function getPreference(string $setting_name, string $default = ''): string 92 { 93 $preference = Session::get('_GUEST_' . $setting_name); 94 95 return is_string($preference) ? $preference : $default; 96 } 97 98 /** 99 * @param string $setting_name 100 * @param string $setting_value 101 * 102 * @return void 103 */ 104 public function setPreference(string $setting_name, string $setting_value): void 105 { 106 Session::put('_GUEST_' . $setting_name, $setting_value); 107 } 108} 109