1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Votifier PHP Client |
5
|
|
|
* |
6
|
|
|
* @package VotifierClient |
7
|
|
|
* @author Manuele Vaccari <[email protected]> |
8
|
|
|
* @copyright Copyright (c) 2017-2020 Manuele Vaccari <[email protected]> |
9
|
|
|
* @license https://github.com/D3strukt0r/votifier-client-php/blob/master/LICENSE.txt GNU General Public License v3.0 |
10
|
|
|
* @link https://github.com/D3strukt0r/votifier-client-php |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace D3strukt0r\VotifierClient\VoteType; |
14
|
|
|
|
15
|
|
|
use DateTime; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* The classic vote package can be used by most plugins. |
19
|
|
|
*/ |
20
|
|
|
class ClassicVote implements VoteInterface |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var string the name of the list/service |
24
|
|
|
*/ |
25
|
|
|
private $serviceName; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var string the username who wants to receive the rewards |
29
|
|
|
*/ |
30
|
|
|
private $username; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string the IP Address of the user |
34
|
|
|
*/ |
35
|
|
|
private $address; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var DateTime|null the time when the vote will be sent |
39
|
|
|
*/ |
40
|
|
|
private $timestamp; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Creates the ClassicVote object. |
44
|
|
|
* |
45
|
|
|
* @param string $username (Required) The username who wants to receive the rewards |
46
|
|
|
* @param string $serviceName (Required) The name of the list/service |
47
|
|
|
* @param string $address (Required) The IP Address of the user |
48
|
|
|
* @param DateTime|null $timestamp (Optional) The time when the vote will be sent |
49
|
|
|
*/ |
50
|
3 |
|
public function __construct(string $username, string $serviceName, string $address, DateTime $timestamp = null) |
51
|
|
|
{ |
52
|
|
|
// Replace username to letters, numbers and "_" |
53
|
3 |
|
$this->username = preg_replace('/[^A-Za-z0-9_]+/', '', $username); |
54
|
3 |
|
$this->serviceName = $serviceName; |
55
|
3 |
|
$this->address = $address; |
56
|
3 |
|
$this->timestamp = $timestamp; |
57
|
3 |
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritdoc} |
61
|
|
|
*/ |
62
|
1 |
|
public function getServiceName(): string |
63
|
|
|
{ |
64
|
1 |
|
return $this->serviceName; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritdoc} |
69
|
|
|
*/ |
70
|
1 |
|
public function getUsername(): string |
71
|
|
|
{ |
72
|
1 |
|
return $this->username; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* {@inheritdoc} |
77
|
|
|
*/ |
78
|
1 |
|
public function getAddress(): string |
79
|
|
|
{ |
80
|
1 |
|
return $this->address; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* {@inheritdoc} |
85
|
|
|
*/ |
86
|
2 |
|
public function getTimestamp(): ?int |
87
|
|
|
{ |
88
|
2 |
|
if (null !== $this->timestamp) { |
89
|
1 |
|
return $this->timestamp->getTimestamp(); |
90
|
|
|
} |
91
|
|
|
|
92
|
1 |
|
return null; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* {@inheritdoc} |
97
|
|
|
*/ |
98
|
1 |
|
public function setTimestamp(DateTime $timestamp = null): self |
99
|
|
|
{ |
100
|
1 |
|
$this->timestamp = $timestamp ?: new DateTime(); |
101
|
|
|
|
102
|
1 |
|
return $this; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|