\Zyberspace\Telegram\CliRawClient

Raw part of the php-client for telegram-cli.

Takes care of the socket-connection and some helper-methods.

Summary

Methods
Properties
Constants
__construct()
__destruct()
exec()
getErrorMessage()
getErrorCode()
escapeStringArgument()
escapePeer()
formatPeerList()
formatFileName()
No public properties found
No constants found
No protected methods found
$_fp
$_errorMessage
$_errorCode
N/A
No private methods found
No private properties found
N/A

Properties

$_fp

$_fp : \Zyberspace\Telegram\Cli\ressource

The file handler for the socket-connection

Type

\Zyberspace\Telegram\Cli\ressource

$_errorMessage

$_errorMessage : string

If telegram-cli returns an error, the error-message gets stored here.

Type

string

$_errorCode

$_errorCode : integer

If telegram-cli returns an error, the error-code gets stored here.

Type

integer

Methods

__construct()

__construct(string  $remoteSocket) 

Connects to the telegram-cli.

Parameters

string $remoteSocket

Address of the socket to connect to. See stream_socket_client() for more info. Can be 'unix://' or 'tcp://'.

Throws

\Zyberspace\Telegram\Cli\ClientException

Throws an exception if no connection can be established.

__destruct()

__destruct() 

Closes the connection to the telegram-cli.

exec()

exec(string  $command) : object|boolean

Executes a command on the telegram-cli. Line-breaks will be escaped, as telgram-cli does not support them.

Parameters

string $command

The command. Command-arguments can be passed as additional method-arguments.

Returns

object|boolean —

Returns the answer as a json-object or true on success, false if there was an error.

getErrorMessage()

getErrorMessage() : string|null

Returns the error-message retrieved vom telegram-cli, if there is one.

Returns

string|null —

The error-message retrieved from telegram-cli or null if there was no error.

getErrorCode()

getErrorCode() : string|null

Returns the error-code retrieved vom telegram-cli, if there is one.

Returns

string|null —

The error-message retrieved from telegram-cli or null if there was no error.

escapeStringArgument()

escapeStringArgument(string  $argument) : string

Escapes strings for usage as command-argument.

T"es't -> "T\"es\'t"

Parameters

string $argument

The argument to escape

Returns

string —

The escaped command enclosed by double-quotes

escapePeer()

escapePeer(string  $peer) : string

Replaces all spaces with underscores.

Parameters

string $peer

The peer to escape

Returns

string —

The escaped peer

formatPeerList()

formatPeerList(array  $peerList) : string

Takes a list of peers and turns it into a format needed by the most commands that handle multiple peers.

Every single peer gets escaped by escapePeer().

Parameters

array $peerList

The list of peers that shall get formated

Returns

string —

The formated list of peers

formatFileName()

formatFileName(string  $fileName) : string

Turns the given $fileName into an absolute file path and escapes him

Parameters

string $fileName

The path to the file (can be relative or absolute)

Returns

string —

The absolute path to the file