|
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; |
|
14
|
|
|
|
|
15
|
|
|
use D3strukt0r\VotifierClient\ServerType\ServerTypeInterface; |
|
16
|
|
|
use D3strukt0r\VotifierClient\VoteType\VoteInterface; |
|
17
|
|
|
use DateTime; |
|
18
|
|
|
use Exception; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* This class is used for easy access to all classes and to send the votes. |
|
22
|
|
|
*/ |
|
23
|
|
|
class Vote |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var VoteInterface the vote package |
|
27
|
|
|
*/ |
|
28
|
|
|
private $vote; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var ServerTypeInterface the server type information package |
|
32
|
|
|
*/ |
|
33
|
|
|
private $server; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Gets the vote. |
|
37
|
|
|
* |
|
38
|
|
|
* @return VoteInterface return the vote |
|
39
|
|
|
*/ |
|
40
|
1 |
|
public function getVote(): VoteInterface |
|
41
|
|
|
{ |
|
42
|
1 |
|
return $this->vote; |
|
43
|
1 |
|
} |
|
44
|
1 |
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Sets the vote. |
|
47
|
|
|
* |
|
48
|
|
|
* @param VoteInterface $vote The vote |
|
49
|
|
|
* |
|
50
|
|
|
* @return $this returns the class itself, for doing multiple things at once |
|
51
|
|
|
*/ |
|
52
|
|
|
public function setVote(VoteInterface $vote): self |
|
53
|
|
|
{ |
|
54
|
|
|
$this->vote = $vote; |
|
55
|
|
|
|
|
56
|
|
|
return $this; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Gets the server type. |
|
61
|
|
|
* |
|
62
|
|
|
* @return ServerTypeInterface returns the server type |
|
63
|
|
|
*/ |
|
64
|
|
|
public function getServerType(): ServerTypeInterface |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->server; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Sets the server type. |
|
71
|
|
|
* |
|
72
|
|
|
* @param ServerTypeInterface $server The server type |
|
73
|
|
|
* |
|
74
|
|
|
* @return $this returns the class itself, for doing multiple things at once |
|
75
|
|
|
*/ |
|
76
|
|
|
public function setServerType(ServerTypeInterface $server): self |
|
77
|
|
|
{ |
|
78
|
|
|
$this->server = $server; |
|
79
|
|
|
|
|
80
|
|
|
return $this; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @param DateTime|null $timestamp [optional] A timestamp |
|
85
|
|
|
* |
|
86
|
|
|
* @throws Exception |
|
87
|
|
|
*/ |
|
88
|
|
|
public function send(DateTime $timestamp = null): void |
|
89
|
|
|
{ |
|
90
|
|
|
$con = new ServerConnection($this->server); |
|
91
|
|
|
|
|
92
|
|
|
$timestamp = $timestamp ?: new DateTime(); |
|
93
|
|
|
$this->vote->setTimestamp($timestamp); |
|
94
|
|
|
$this->server->send($con, $this->vote); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|