-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathActiveUser.php
More file actions
42 lines (34 loc) · 746 Bytes
/
ActiveUser.php
File metadata and controls
42 lines (34 loc) · 746 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
declare(strict_types=1);
namespace App\Creational\Singleton;
final class ActiveUser
{
private string $email;
private static ActiveUser $instance;
private function __construct()
{
// Email is retrieved from a db
$this->email = "active@user.com";
}
private function __clone()
{
}
private function __wakeup(): void
{
}
public function setEmail(string $email): void
{
$this->email = $email;
}
public function getEmail(): string
{
return $this->email;
}
public static function getInstance(): self
{
if (!self::$instance) {
self::$instance = new ActiveUser();
}
return self::$instance;
}
}