PEAR2_Net_RouterOS
1.0.0b5
A MikroTik RouterOS client
|
Public Member Functions | |
__construct ($host, $username, $password= '', $port=8728, $persist=false, $timeout=null, $crypto=N::CRYPTO_OFF, $context=null) | |
Creates a new instance of a RouterOS API client. More... | |
__invoke ($arg=null) | |
A shorthand gateway. More... | |
setCharset ($charset, $charsetType=Communicator::CHARSET_ALL) | |
Sets the charset(s) for this connection. More... | |
getCharset ($charsetType) | |
Gets the charset(s) for this connection. More... | |
sendAsync (Request $request, $callback=null) | |
Sends a request and waits for responses. More... | |
isRequestActive ($tag, $filter=self::FILTER_ALL) | |
Checks if a request is active. More... | |
sendSync (Request $request) | |
Sends a request and gets the full response. More... | |
completeRequest ($tag=null) | |
Completes a specified request. More... | |
extractNewResponses ($tag=null) | |
Extracts responses for a request. More... | |
loop ($sTimeout=null, $usTimeout=0) | |
Starts an event loop for the RouterOS callbacks. More... | |
getPendingRequestsCount () | |
Gets the number of pending requests. More... | |
cancelRequest ($tag=null) | |
Cancels a request. More... | |
setStreamingResponses ($streamingResponses) | |
Sets response streaming setting. More... | |
isStreamingResponses () | |
Gets response streaming setting. More... | |
close () | |
Closes the opened connection, even if it is a persistent one. More... | |
__destruct () | |
Closes the connection, unless it's a persistent one. More... | |
Static Public Member Functions | |
static | login (Communicator $com, $username, $password= '', $timeout=null) |
Login to a RouterOS connection. More... | |
Data Fields | |
const | FILTER_CALLBACK = 1 |
Used in static::isRequestActive() to limit search only to requests that have a callback. More... | |
const | FILTER_BUFFER = 2 |
Used in static::isRequestActive() to limit search only to requests that use the buffer. More... | |
const | FILTER_ALL = 3 |
Used in static::isRequestActive() to indicate no limit in search. More... | |
Protected Member Functions | |
send (Request $request) | |
Sends a request to RouterOS. More... | |
dispatchNextResponse ($sTimeout=0, $usTimeout=0) | |
Dispatches the next response in queue. More... | |
Protected Attributes | |
$com | |
$pendingRequestsCount = 0 | |
$responseBuffer = array() | |
$callbacks = array() | |
$registry = null | |
Definition at line 49 of file Client.php.
__construct | ( | $host, | |
$username, | |||
$password = '' , |
|||
$port = 8728 , |
|||
$persist = false , |
|||
$timeout = null , |
|||
$crypto = N::CRYPTO_OFF , |
|||
$context = null |
|||
) |
Creates a new instance of a RouterOS API client.
Creates a new instance of a RouterOS API client with the specified settings.
string | $host | Hostname (IP or domain) of the RouterOS server. |
string | $username | The RouterOS username. |
string | $password | The RouterOS password. |
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 | $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 128 of file Client.php.
__destruct | ( | ) |
Closes the connection, unless it's a persistent one.
Definition at line 745 of file Client.php.
__invoke | ( | $arg = 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.
mixed | $arg | Value can be either a Request to send, which would be sent asynchoniously if it has a tag, and synchroniously if not, a number to loop with or NULL to complete all pending requests. Any other value is converted to string and treated as the tag of a request to complete. |
Definition at line 188 of file Client.php.
cancelRequest | ( | $tag = null | ) |
Cancels a request.
Cancels an active request. Using this function in favor of a plain call to the "/cancel" command is highly reccomended, as it also updates the counter of pending requests properly. Note that canceling a request also removes any responses for it that were not previously extracted with static::extractNewResponses().
string | $tag | Tag of the request to cancel. Setting NULL will cancel all requests. |
Definition at line 608 of file Client.php.
close | ( | ) |
Closes the opened connection, even if it is a persistent one.
Closes the opened connection, even if it is a persistent one. Note that static::extractNewResponses() can still be used to extract responses collected prior to the closing.
Definition at line 706 of file Client.php.
completeRequest | ( | $tag = null | ) |
Completes a specified request.
Starts an event loop for the RouterOS callbacks and finishes when a specified request is completed.
string | $tag | The tag of the request to complete. Setting NULL completes all requests. |
Definition at line 450 of file Client.php.
|
protected |
Dispatches the next response in queue.
Dispatches the next response in queue, i.e. it executes the associated callback if there is one, or places the response in the response buffer.
int | $sTimeout | If a response is not immediatly available, wait this many seconds. If NULL, wait indefinetly. |
int | $usTimeout | Microseconds to add to the waiting time. |
SocketException | When there's no response within the time limit. |
Definition at line 785 of file Client.php.
extractNewResponses | ( | $tag = null | ) |
Extracts responses for a request.
Gets all new responses for a request that haven't been passed to a callback and clears the buffer from them.
string | $tag | The tag of the request to extract new responses for. Specifying NULL with extract new responses for all requests. |
Definition at line 492 of file Client.php.
getCharset | ( | $charsetType | ) |
Gets the charset(s) for this connection.
int | $charsetType | Which charset to get. Valid values are the Communicator::CHARSET_* constants. Any other value is treated as Communicator::CHARSET_ALL. |
Definition at line 332 of file Client.php.
getPendingRequestsCount | ( | ) |
Gets the number of pending requests.
Definition at line 587 of file Client.php.
isRequestActive | ( | $tag, | |
$filter = self::FILTER_ALL |
|||
) |
Checks if a request is active.
Checks if a request is active. A request is considered active if it's a pending request and/or has responses that are not yet extracted.
string | $tag | The tag of the request to look for. |
int | $filter | One of the FILTER_* consntants. Limits the search to the specified places. |
Definition at line 403 of file Client.php.
isStreamingResponses | ( | ) |
Gets response streaming setting.
Gets whether future responses are streamed.
Definition at line 692 of file Client.php.
|
static |
Login to a RouterOS connection.
Communicator | $com | The communicator to attempt to login to. |
string | $username | The RouterOS username. |
string | $password | The RouterOS password. |
int | null | $timeout | The time to wait for each response. NULL waits indefinetly. |
Definition at line 212 of file Client.php.
loop | ( | $sTimeout = null , |
|
$usTimeout = 0 |
|||
) |
Starts an event loop for the RouterOS callbacks.
Starts an event loop for the RouterOS callbacks and finishes when there are no more pending requests or when a specified timeout has passed (whichever comes first).
int | $sTimeout | Timeout for the loop. If NULL, there is no time limit. |
int | $usTimeout | Microseconds to add to the time limit. |
Definition at line 539 of file Client.php.
|
protected |
Sends a request to RouterOS.
Request | $request | The request to send. |
Definition at line 765 of file Client.php.
sendAsync | ( | Request | $request, |
$callback = null |
|||
) |
Sends a request and waits for responses.
Request | $request | The request to send. |
callback | $callback | Optional. A function that is to be executed when new responses for this request are available. The callback takes two parameters. The Response object as the first, and the Client object as the second one. If the function returns TRUE, the request is canceled. Note that the callback may be executed one last time after that with a response that notifies about the canceling. |
Definition at line 354 of file Client.php.
sendSync | ( | Request | $request | ) |
Sends a request and gets the full response.
Request | $request | The request to send. |
Definition at line 424 of file Client.php.
setCharset | ( | $charset, | |
$charsetType = Communicator::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 requests and responses. When sending, Communicator::CHARSET_LOCAL is converted to Communicator::CHARSET_REMOTE, and when receiving, Communicator::CHARSET_REMOTE is converted to Communicator::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 Communicator::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 Communicator::CHARSET_* constants. Any other value is treated as Communicator::CHARSET_ALL. |
Definition at line 313 of file Client.php.
setStreamingResponses | ( | $streamingResponses | ) |
Sets response streaming setting.
Sets whether future responses are streamed. If responses are streamed, the argument values are returned as streams instead of strings. This is particularly useful if you expect a response that may contain one or more very large words.
bool | $streamingResponses | Whether to stream future responses. |
Definition at line 677 of file Client.php.
|
protected |
Definition at line 87 of file Client.php.
|
protected |
Definition at line 69 of file Client.php.
|
protected |
Definition at line 74 of file Client.php.
|
protected |
Definition at line 93 of file Client.php.
|
protected |
Definition at line 81 of file Client.php.
const FILTER_ALL = 3 |
Used in static::isRequestActive() to indicate no limit in search.
Definition at line 64 of file Client.php.
const FILTER_BUFFER = 2 |
Used in static::isRequestActive() to limit search only to requests that use the buffer.
Definition at line 60 of file Client.php.
const FILTER_CALLBACK = 1 |
Used in static::isRequestActive() to limit search only to requests that have a callback.
Definition at line 55 of file Client.php.