PEAR2_Net_RouterOS
1.0.0b6
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 | verifyLengthSupport ($length) |
Verifies that the length is supported. More... | |
static | encodeLength ($length) |
Encodes the length as required by the RouterOS API. More... | |
static | decodeLength (T\Stream $trans) |
Decodes the length of the incoming message. More... | |
Data Fields | |
const | CHARSET_ALL = -1 |
Used when getting/setting all (default) charsets. | |
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... | |
Protected Attributes | |
$charsets = array() | |
$trans | |
Static Protected Attributes | |
static | $defaultCharsets |
Definition at line 45 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 RouterOS. |
int | null | $port | The port on which the RouterOS host 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. |
double | null | $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 PEAR2CRYPTO_* 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 | null | $context | A context for the socket. |
Definition at line 123 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 | null | $string | A string of the word to send, or NULL to get the next word as a string. |
Definition at line 194 of file Communicator.php.
close | ( | ) |
Closes the opened connection, even if it is a persistent one.
Definition at line 699 of file Communicator.php.
|
static |
Decodes the length of the incoming message.
Decodes the length 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 640 of file Communicator.php.
|
static |
Encodes the length as required by the RouterOS API.
int | $length | The length to encode. |
Definition at line 515 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 385 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 303 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 558 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 597 of file Communicator.php.
getTransmitter | ( | ) |
Gets the transmitter for this connection.
Definition at line 396 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 229 of file Communicator.php.
|
static |
Checks whether a variable is a seekable stream resource.
mixed | $var | The value to check. |
Definition at line 207 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 320 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 413 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 450 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 conversion, 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 354 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 271 of file Communicator.php.
|
static |
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 496 of file Communicator.php.
|
staticprotected |
Definition at line 77 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 68 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 59 of file Communicator.php.