PEAR2_Net_RouterOS
1.0.0b5
A MikroTik RouterOS client
|
Public Member Functions | |
__construct ($host, $port=8728, $persist=false, $timeout=null, $key= '', $crypto=T\NetworkStream::CRYPTO_OFF, $context=null) | |
Creates a new connection with the specified options. More... | |
__invoke ($string=null) | |
A shorthand gateway. More... | |
setCharset ($charset, $charsetType=self::CHARSET_ALL) | |
Sets the charset(s) for this connection. More... | |
getCharset ($charsetType) | |
Gets the charset(s) for this connection. More... | |
getTransmitter () | |
Gets the transmitter for this connection. More... | |
sendWord ($word) | |
Sends a word. More... | |
sendWordFromStream ($prefix, $stream) | |
Sends a word based on a stream. More... | |
getNextWord () | |
Get the next word in queue as a string. More... | |
getNextWordAsStream () | |
Get the next word in queue as a stream. More... | |
close () | |
Closes the opened connection, even if it is a persistent one. More... | |
Static Public Member Functions | |
static | isSeekableStream ($var) |
Checks whether a variable is a seekable stream resource. More... | |
static | iconvStream ($inCharset, $outCharset, $stream) |
Uses iconv to convert a stream from one charset to another. More... | |
static | setDefaultCharset ($charset, $charsetType=self::CHARSET_ALL) |
Sets the default charset(s) for new connections. More... | |
static | getDefaultCharset ($charsetType) |
Gets the default charset(s). More... | |
static | seekableStreamLength ($stream) |
Gets the length of a seekable stream. More... | |
static | encodeLength ($length) |
Encodes the length as requred by the RouterOS API. More... | |
static | decodeLength (T\Stream $trans) |
Decodes the lenght of the incoming message. More... | |
Data Fields | |
const | CHARSET_ALL = -1 |
Used when getting/setting all (default) charsets. More... | |
const | CHARSET_REMOTE = 0 |
Used when getting/setting the (default) remote charset. More... | |
const | CHARSET_LOCAL = 1 |
Used when getting/setting the (default) local charset. More... | |
Static Protected Member Functions | |
static | verifyLengthSupport ($length) |
Verifies that the length is supported. More... | |
Protected Attributes | |
$charsets = array() | |
$trans | |
Static Protected Attributes | |
static | $defaultCharsets |
Definition at line 44 of file Communicator.php.
__construct | ( | $host, | |
$port = 8728 , |
|||
$persist = false , |
|||
$timeout = null , |
|||
$key = '' , |
|||
$crypto = T\NetworkStream::CRYPTO_OFF , |
|||
$context = null |
|||
) |
Creates a new connection with the specified options.
string | $host | Hostname (IP or domain) of the RouterOS server. |
int | null | $port | The port on which the RouterOS server provides the API service. You can also specify NULL, in which case the port will automatically be chosen between 8728 and 8729, depending on the value of $crypto. |
bool | $persist | Whether or not the connection should be a persistent one. |
float | $timeout | The timeout for the connection. |
string | $key | A string that uniquely identifies the connection. |
string | $crypto | The encryption for this connection. Must be one of the PEAR2::CRYPTO_* constants. Off by default. RouterOS currently supports only TLS, but the setting is provided in this fashion for forward compatibility's sake. And for the sake of simplicity, if you specify an encryption, don't specify a context and your default context uses the value "DEFAULT" for ciphers, "ADH" will be automatically added to the list of ciphers. |
resource | $context | A context for the socket. |
Definition at line 113 of file Communicator.php.
__invoke | ( | $string = null | ) |
A shorthand gateway.
This is a magic PHP method that allows you to call the object as a function. Depending on the argument given, one of the other functions in the class is invoked and its returned value is returned by this function.
string | $string | A string of the word to send, or NULL to get the next word as a string. |
Definition at line 175 of file Communicator.php.
close | ( | ) |
Closes the opened connection, even if it is a persistent one.
Definition at line 667 of file Communicator.php.
|
static |
Decodes the lenght of the incoming message.
Decodes the lenght of the incoming message, as specified by the RouterOS API.
T\Stream | $trans | The transmitter from which to decode the length of the incoming message. |
Definition at line 609 of file Communicator.php.
|
static |
Encodes the length as requred by the RouterOS API.
int | $length | The length to encode. |
Definition at line 487 of file Communicator.php.
getCharset | ( | $charsetType | ) |
Gets the charset(s) for this connection.
int | $charsetType | Which charset to get. Valid values are the CHARSET_* constants. Any other value is treated as self::CHARSET_ALL. |
Definition at line 359 of file Communicator.php.
|
static |
Gets the default charset(s).
int | $charsetType | Which charset to get. Valid values are the CHARSET_* constants. Any other value is treated as self::CHARSET_ALL. |
Definition at line 279 of file Communicator.php.
getNextWord | ( | ) |
Get the next word in queue as a string.
Get the next word in queue as a string, after automatically decoding its length.
Definition at line 529 of file Communicator.php.
getNextWordAsStream | ( | ) |
Get the next word in queue as a stream.
Get the next word in queue as a stream, after automatically decoding its length.
Definition at line 567 of file Communicator.php.
getTransmitter | ( | ) |
Gets the transmitter for this connection.
Definition at line 370 of file Communicator.php.
|
static |
Uses iconv to convert a stream from one charset to another.
string | $inCharset | The charset of the stream. |
string | $outCharset | The desired resulting charset. |
resource | $stream | The stream to convert. The stream is assumed to be seekable, and is read from its current position to its end, after which, it is seeked back to its starting position. |
Definition at line 210 of file Communicator.php.
|
static |
Checks whether a variable is a seekable stream resource.
mixed | $var | The value to check. |
Definition at line 188 of file Communicator.php.
|
static |
Gets the length of a seekable stream.
Gets the length of a seekable stream.
resource | $stream | The stream to check. The stream is assumed to be seekable. |
Definition at line 296 of file Communicator.php.
sendWord | ( | $word | ) |
Sends a word.
Sends a word and automatically encodes its length when doing so.
string | $word | The word to send. |
Definition at line 386 of file Communicator.php.
sendWordFromStream | ( | $prefix, | |
$stream | |||
) |
Sends a word based on a stream.
Sends a word based on a stream and automatically encodes its length when doing so. The stream is read from its current position to its end, and then returned to its current position. Because of those operations, the supplied stream must be seekable.
string | $prefix | A string to prepend before the stream contents. |
resource | $stream | The seekable stream to send. |
Definition at line 422 of file Communicator.php.
setCharset | ( | $charset, | |
$charsetType = self::CHARSET_ALL |
|||
) |
Sets the charset(s) for this connection.
Sets the charset(s) for this connection. The specified charset(s) will be used for all future words. When sending, self::CHARSET_LOCAL is converted to self::CHARSET_REMOTE, and when receiving, self::CHARSET_REMOTE is converted to self::CHARSET_LOCAL. Setting NULL to either charset will disable charset convertion, and data will be both sent and received "as is".
mixed | $charset | The charset to set. If $charsetType is self::CHARSET_ALL, you can supply either a string to use for all charsets, or an array with the charset types as keys, and the charsets as values. |
int | $charsetType | Which charset to set. Valid values are the CHARSET_* constants. Any other value is treated as self::CHARSET_ALL. |
Definition at line 329 of file Communicator.php.
|
static |
Sets the default charset(s) for new connections.
mixed | $charset | The charset to set. If $charsetType is self::CHARSET_ALL, you can supply either a string to use for all charsets, or an array with the charset types as keys, and the charsets as values. |
int | $charsetType | Which charset to set. Valid values are the CHARSET_* constants. Any other value is treated as self::CHARSET_ALL. |
Definition at line 248 of file Communicator.php.
|
staticprotected |
Verifies that the length is supported.
Verifies if the specified length is supported by the API. Throws a LengthException if that's not the case. Currently, RouterOS supports words up to 0xFFFFFFFF in length, so that's the only check performed.
int | $length | The length to verify. |
Definition at line 468 of file Communicator.php.
|
protected |
Definition at line 82 of file Communicator.php.
|
staticprotected |
Definition at line 73 of file Communicator.php.
|
protected |
Definition at line 87 of file Communicator.php.
const CHARSET_ALL = -1 |
Used when getting/setting all (default) charsets.
Definition at line 49 of file Communicator.php.
const CHARSET_LOCAL = 1 |
Used when getting/setting the (default) local charset.
The local charset is the charset in which the data from RouterOS will be returned as. This charset should match the charset of the place the data will eventually be written to.
Definition at line 67 of file Communicator.php.
const CHARSET_REMOTE = 0 |
Used when getting/setting the (default) remote charset.
The remote charset is the charset in which RouterOS stores its data. If you want to keep compatibility with your Winbox, this charset should match the default charset from your Windows' regional settings.
Definition at line 58 of file Communicator.php.