\D3strukt0r\Votifier\Client\Server

Votifier

class D3strukt0r\Votifier\Client\Server\Votifier

The Class to access a server which uses the classic “Votifier” plugin.

protected property $socket

D3strukt0r\Votifier\Client\Socket — The socket object

protected property $host

string — The domain or ip to connect to Votifier

protected property $port

int — The port which votifier uses on the server

protected property $publicKey

string — The public.key which is generated by the plugin

public getSocket() → Socket

Gets the Socket.

Returns:D3strukt0r\Votifier\Client\Socket — Returns a Socket object
public setSocket($socket) → $this

Sets the Socket.

Parameters:
  • $socket (string) – The socket object
Returns:

$this — Returns the class itself, for doing multiple things at once

public getHost() → string|null

Gets the host.

Returns:string|null — Returns the host
public setHost($host) → $this

Sets the host.

Parameters:
  • $host (string) – The host
Returns:

$this — Returns the class itself, for doing multiple things at once

public getPort() → int

Gets the port.

Returns:int — Returns the port
public setPort($port) → $this

Sets the port.

Parameters:
  • $port (int) – The port
Returns:

$this — Returns the class itself, for doing multiple things at once

public getPublicKey() → string|null

Gets the public key.

Returns:string|null — Returns the public key
public setPublicKey($publicKey) → $this

Sets the public key.

Parameters:
  • $publicKey (string) – The public key
Returns:

$this — Returns the class itself, for doing multiple things at once

public verifyConnection()

Checks if the server actually belongs to Votifier.

Throws:

InvalidArgumentException

If one required parameter wasn’t set

Throws:

D3strukt0r\Votifier\Client\Exception\Socket\NoConnectionException

If connection couldn’t be established

Throws:

D3strukt0r\Votifier\Client\Exception\Socket\PackageNotReceivedException

If there was an error receiving the package

Throws:

D3strukt0r\Votifier\Client\Exception\NotVotifierException

If the server we are connected to is not a valid Votifier server

public sendVote(...$votes)

Sends the vote packages to the server.

Parameters:
  • $votes (\D3strukt0r\Votifier\Client\Vote\VoteInterface) – The vote packages
Throws:

InvalidArgumentException

If one required parameter wasn’t set

Throws:

D3strukt0r\Votifier\Client\Exception\Socket\NoConnectionException

If connection couldn’t be established

Throws:

D3strukt0r\Votifier\Client\Exception\Socket\PackageNotSentException

If there was an error receiving the package

Throws:

D3strukt0r\Votifier\Client\Exception\Socket\PackageNotReceivedException

If there was an error sending the package

Throws:

D3strukt0r\Votifier\Client\Exception\NotVotifierException

If the server we are connected to is not a valid Votifier server

protected checkRequiredVariablesForSocket()

Check that both host and port have been set.

Throws:InvalidArgumentException — If one required parameter wasn’t set
protected checkRequiredVariablesForPackage($vote)

Check that service name, username, address, timestamp and public key have been set.

Parameters:
  • $vote (D3strukt0r\Votifier\Client\Vote\VoteInterface) – The vote to check
Throws:

InvalidArgumentException — If one required parameter wasn’t set

protected verifyConnection($header) → bool

Verifies that the connection is correct.

Parameters:
  • $header (string|null) – The header that the plugin usually sends
Returns:

bool — Returns true if connections is available, otherwise false

protected preparePackage($vote) → string

Create encrypted package for default Votifier.

Parameters:
  • $vote (\D3strukt0r\Votifier\Client\Vote\VoteInterface) – The vote package with all the information
Returns:

string — Returns the string to be sent to the server