Repository navigation
Expand file tree
/
Copy pathMeta.php
More file actions
98 lines (81 loc) · 1.94 KB
/
Copy pathMeta.php
File metadata and controls
98 lines (81 loc) · 1.94 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Snowflake;
class Meta
{
/**
* @var int [0, 31]
*/
protected int $dataCenterId;
/**
* @var int [0, 31]
*/
protected int $workerId;
/**
* @var int [0, 4095]
*/
protected int $sequence;
/**
* @var int seconds or milliseconds
*/
protected int $timestamp = 0;
/**
* @var int seconds or milliseconds
*/
protected int $beginTimestamp = 0;
public function __construct(int $dataCenterId, int $workerId, int $sequence, int $timestamp, int $beginTimestamp = 1560960000)
{
$this->dataCenterId = $dataCenterId;
$this->workerId = $workerId;
$this->sequence = $sequence;
$this->timestamp = $timestamp;
$this->beginTimestamp = $beginTimestamp;
}
public function getTimeInterval(): int
{
return $this->timestamp - $this->beginTimestamp;
}
public function getDataCenterId(): int
{
return $this->dataCenterId;
}
public function getWorkerId(): int
{
return $this->workerId;
}
public function getSequence(): int
{
return $this->sequence;
}
public function setDataCenterId(int $dataCenterId): self
{
$this->dataCenterId = $dataCenterId;
return $this;
}
public function setWorkerId(int $workerId): self
{
$this->workerId = $workerId;
return $this;
}
public function setSequence(int $sequence): self
{
$this->sequence = $sequence;
return $this;
}
public function getTimestamp(): int
{
return $this->timestamp;
}
public function getBeginTimestamp(): int
{
return $this->beginTimestamp;
}
}