Communicator.php
- Author
- Vasil Rangelov
- Category
- Net
- Copyright
- 2011 Vasil Rangelov
- License
- LGPL License 2.1
- Link
- http://pear2.php.net/PEAR2_Net_RouterOS
- Package
- PEAR2_Net_RouterOS
- Version
- 1.0.0b4
\PEAR2\Net\RouterOS\Communicator
- See
- Author
- Vasil Rangelov
- Category
- Net
- License
- LGPL License 2.1
- Link
- http://pear2.php.net/PEAR2_Net_RouterOS
Constants
CHARSET_REMOTE
= 0Properties

array $charsets = array()An array with the current charset types as keys, and the current charsets as values.
array()Details- Type
- array

array $defaultCharsets = array(self::CHARSET_REMOTE => null, self::CHARSET_LOCAL => null)An array with the default charset types as keys, and the default charsets as values.
array(self::CHARSET_REMOTE => null, self::CHARSET_LOCAL => null)Details- Type
- array
Methods

__construct(string $host, int | null $port = 8728, bool $persist = false, float $timeout = null, string $key = '', string $crypto = \PEAR2\Net\Transmitter\NetworkStream::CRYPTO_OFF, resource $context = null) : voidCreates a new connection with the specified options.
| Name | Type | Description |
|---|---|---|
| $host | string | Hostname (IP or domain) of the RouterOS server. |
| $port | int | null | 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. |
| $persist | bool | Whether or not the connection should be a persistent one. |
| $timeout | float | The timeout for the connection. |
| $key | string | A string that uniquely identifies the connection. |
| $crypto | string | The encryption for this connection. Must be one of the PEAR2\Net\Transmitter\NetworkStream::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. |
| $context | resource | A context for the socket. |

__invoke(string $string = null) : int | stringA shorthand gateway.
| Name | Type | Description |
|---|---|---|
| $string | string | A string of the word to send, or NULL to get the next word as a string. |
| Type | Description |
|---|---|
| int | string | If a string is provided, returns the number of bytes sent, otherwise retuns the next word as a string. |

_decodeLength(\PEAR2\Net\Transmitter\Stream $trans) : intDecodes the lenght of the incoming message.
| Name | Type | Description |
|---|---|---|
| $trans | \PEAR2\Net\Transmitter\Stream | The transmitter from which to decode the length of the incoming message. |
| Type | Description |
|---|---|
| int | The decoded length. |

close() : boolCloses the opened connection, even if it is a persistent one.
| Type | Description |
|---|---|
| bool | TRUE on success, FALSE on failure. |

decodeLength(\PEAR2\Net\Transmitter\Stream $trans) : intDecodes the lenght of the incoming message.
| Name | Type | Description |
|---|---|---|
| $trans | \PEAR2\Net\Transmitter\Stream | The transmitter from which to decode the length of the incoming message. |
| Type | Description |
|---|---|
| int | The decoded length. |

encodeLength(int $length) : stringEncodes the length as requred by the RouterOS API.
| Name | Type | Description |
|---|---|---|
| $length | int | The length to encode. |
| Type | Description |
|---|---|
| string | The encoded length. |

getCharset(int $charsetType) : string | arrayGets the charset(s) for this connection.
| Name | Type | Description |
|---|---|---|
| $charsetType | int | Which charset to get. Valid values are the CHARSET_* constants. Any other value is treated as {@link CHARSET_ALL}. |
| Type | Description |
|---|---|
| string | array | The current charset. If $charsetType is {@link CHARSET_ALL}, the current values will be returned as an array with the types as keys, and charsets as values. |

getDefaultCharset(int $charsetType) : string | arrayGets the default charset(s).
| Name | Type | Description |
|---|---|---|
| $charsetType | int | Which charset to get. Valid values are the CHARSET_* constants. Any other value is treated as {@link CHARSET_ALL}. |
| Type | Description |
|---|---|
| string | array | The current charset. If $charsetType is {@link CHARSET_ALL}, the current values will be returned as an array with the types as keys, and charsets as values. |

getTransmitter() : \PEAR2\Net\Transmitter\TcpClientGets the transmitter for this connection.
| Type | Description |
|---|---|
| \PEAR2\Net\Transmitter\TcpClient | The transmitter for this connection. |

iconvStream(string $in_charset, string $out_charset, resource $stream) : resourceUses iconv to convert a stream from one charset to another.
| Name | Type | Description |
|---|---|---|
| $in_charset | string | The charset of the stream. |
| $out_charset | string | The desired resulting charset. |
| $stream | resource | The stream to convert. |
| Type | Description |
|---|---|
| resource | A new stream that uses the $out_charset. The stream is a subset from the original stream, from its current position to its end. |

isSeekableStream(mixed $var) : boolChecks whether a variable is a seekable stream resource.
| Name | Type | Description |
|---|---|---|
| $var | mixed | The value to check. |
| Type | Description |
|---|---|
| bool | TRUE if $var is a seekable stream, FALSE otherwise. |

sendWordFromStream(string $prefix, resource $stream) : intSends a word based on a stream.
| Name | Type | Description |
|---|---|---|
| $prefix | string | A string to prepend before the stream contents. |
| $stream | resource | The stream to send. |
| Type | Description |
|---|---|
| int | The number of bytes sent. |

setCharset(mixed $charset, int $charsetType = self::CHARSET_ALL) : string | arraySets the charset(s) for this connection.
| Name | Type | Description |
|---|---|---|
| $charset | mixed | The charset to set. If $charsetType is {@link 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. |
| $charsetType | int | Which charset to set. Valid values are the Communicator::CHARSET_* constants. Any other value is treated as {@link CHARSET_ALL}. |
| Type | Description |
|---|---|
| string | array | The old charset. If $charsetType is {@link CHARSET_ALL}, the old values will be returned as an array with the types as keys, and charsets as values. |

setDefaultCharset(mixed $charset, int $charsetType = self::CHARSET_ALL) : string | arraySets the default charset(s) for new connections.
| Name | Type | Description |
|---|---|---|
| $charset | mixed | The charset to set. If $charsetType is {@link 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. |
| $charsetType | int | Which charset to set. Valid values are the CHARSET_* constants. Any other value is treated as {@link CHARSET_ALL}. |
| Type | Description |
|---|---|
| string | array | The old charset. If $charsetType is {@link CHARSET_ALL}, the old values will be returned as an array with the types as keys, and charsets as values. |

verifyLengthSupport(int $length) : voidVerifies that the length is supported.
| Name | Type | Description |
|---|---|---|
| $length | int | The length to verify. |