1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Utilities\Router; |
5
|
|
|
|
6
|
|
|
use Utilities\Common\Common; |
7
|
|
|
use Utilities\Common\Time; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* User class |
11
|
|
|
* |
12
|
|
|
* @link https://github.com/utilities-php/router |
13
|
|
|
* @author Shahrad Elahi (https://github.com/shahradelahi) |
14
|
|
|
* @license https://github.com/utilities-php/router/blob/master/LICENSE (MIT License) |
15
|
|
|
*/ |
16
|
|
|
class User |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var array |
21
|
|
|
*/ |
22
|
|
|
private array $data; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* User constructor. |
26
|
|
|
* |
27
|
|
|
* @param array $extend_data |
28
|
|
|
*/ |
29
|
|
|
public function __construct(array $extend_data = []) |
30
|
|
|
{ |
31
|
|
|
$this->data = array_merge($extend_data, [ |
32
|
|
|
'id' => Common::makeUUID(), |
33
|
|
|
'created_at' => Time::getMillisecond(), |
34
|
|
|
'updated_at' => Time::getMillisecond(), |
35
|
|
|
]); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* put data to user container |
40
|
|
|
* |
41
|
|
|
* @param string $key |
42
|
|
|
* @param mixed $value |
43
|
|
|
* @return array |
44
|
|
|
*/ |
45
|
|
|
public function put(string $key, mixed $value): array |
46
|
|
|
{ |
47
|
|
|
$this->data['container'][$key] = $value; |
48
|
|
|
$this->data['updated_at'] = Time::getMillisecond(); |
49
|
|
|
return $this->data; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* get data from user container |
54
|
|
|
* |
55
|
|
|
* @param string $key |
56
|
|
|
* @return mixed |
57
|
|
|
*/ |
58
|
|
|
public function get(string $key): mixed |
59
|
|
|
{ |
60
|
|
|
return $this->data['container'][$key] ?? null; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* get the timestamp of the user creation |
65
|
|
|
* |
66
|
|
|
* @return int |
67
|
|
|
*/ |
68
|
|
|
public function getCreatedAt(): int |
69
|
|
|
{ |
70
|
|
|
return $this->data['created_at']; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* get the timestamp of the user last update |
75
|
|
|
* |
76
|
|
|
* @return int |
77
|
|
|
*/ |
78
|
|
|
public function getUpdatedAt(): int |
79
|
|
|
{ |
80
|
|
|
return $this->data['updated_at']; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
} |