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\Server; |
14
|
|
|
|
15
|
|
|
use D3strukt0r\VotifierClient\Socket; |
16
|
|
|
|
17
|
|
|
abstract class GenericServerType implements ServerTypeInterface |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var string the domain or ip to connect to Votifier |
21
|
|
|
*/ |
22
|
|
|
private $host; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var int the port which votifier uses on the server |
26
|
|
|
*/ |
27
|
|
|
private $port = 8192; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var string The public.key which is generated by the plugin. |
31
|
|
|
*/ |
32
|
|
|
private $publicKey; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var Socket The socket object |
36
|
|
|
*/ |
37
|
|
|
private $socket; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return Socket returns a Socket object |
41
|
|
|
*/ |
42
|
1 |
|
public function getSocket(): Socket |
43
|
|
|
{ |
44
|
1 |
|
return null === $this->socket ? $this->socket = new Socket() : $this->socket; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param Socket $socket The socket object |
49
|
|
|
* |
50
|
|
|
* @return $this returns the class itself, for doing multiple things at once |
51
|
|
|
*/ |
52
|
1 |
|
public function setSocket(Socket $socket): self |
53
|
|
|
{ |
54
|
1 |
|
$this->socket = $socket; |
55
|
|
|
|
56
|
1 |
|
return $this; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritdoc} |
61
|
|
|
*/ |
62
|
1 |
|
public function getHost(): string |
63
|
|
|
{ |
64
|
1 |
|
return $this->host; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritdoc} |
69
|
|
|
*/ |
70
|
1 |
|
public function setHost(string $host): self |
71
|
|
|
{ |
72
|
1 |
|
$this->host = $host; |
73
|
|
|
|
74
|
1 |
|
return $this; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* {@inheritdoc} |
79
|
|
|
*/ |
80
|
1 |
|
public function getPort(): int |
81
|
|
|
{ |
82
|
1 |
|
return $this->port; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* {@inheritdoc} |
87
|
|
|
*/ |
88
|
1 |
|
public function setPort(int $port) |
89
|
|
|
{ |
90
|
1 |
|
$this->port = $port; |
91
|
|
|
|
92
|
1 |
|
return $this; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* {@inheritdoc} |
97
|
|
|
*/ |
98
|
1 |
|
public function getPublicKey(): string |
99
|
|
|
{ |
100
|
1 |
|
return $this->publicKey; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* {@inheritdoc} |
105
|
|
|
*/ |
106
|
1 |
|
public function setPublicKey(string $publicKey): self |
107
|
|
|
{ |
108
|
1 |
|
$publicKey = wordwrap($publicKey, 65, "\n", true); |
109
|
|
|
$publicKey = <<<EOF |
110
|
1 |
|
-----BEGIN PUBLIC KEY----- |
111
|
1 |
|
{$publicKey} |
112
|
|
|
-----END PUBLIC KEY----- |
113
|
|
|
EOF; |
114
|
1 |
|
$this->publicKey = $publicKey; |
115
|
|
|
|
116
|
1 |
|
return $this; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|