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