Request.php
RouterOS is the flag product of the company MikroTik and is a powerful router software. One of its many abilities is to allow control over it via an API. This package provides a client for that API, in turn allowing you to use PHP to control RouterOS hosts.
PHP version 5
- 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.0b3
\PEAR2\Net\RouterOS\Request
- Parent(s)
- \PEAR2\Net\RouterOS\Message
- Author
- Vasil Rangelov
- Category
- Net
- License
- LGPL License 2.1
- Link
- http://pear2.php.net/PEAR2_Net_RouterOS
Properties


string $_tag = null
An optional tag to associate the message with.
null
Details- Type
- string
- Inherited_from
- \PEAR2\Net\RouterOS\Message::$$_tag


array $arguments = array()
An array with message arguments. Keys are the names of the arguments, array values are values for the corresponding argument.
array()
Details- Type
- array
- Inherited_from
- \PEAR2\Net\RouterOS\Message::$$arguments
Methods


__construct(string $command, \PEAR2\Net\RouterOS\Query $query = null, string $tag = null) : void
Creates a request to send to RouterOS.
Name | Type | Description |
---|---|---|
$command | string | The command to send. Can also contain arguments expressed in a shell-like syntax. |
$query | \PEAR2\Net\RouterOS\Query | A query to associate with the request. |
$tag | string | The tag for the request. |
- See
- \PEAR2\Net\RouterOS\setCommand()
- See
- \PEAR2\Net\RouterOS\setArgument()
- See
- \PEAR2\Net\RouterOS\setTag()
- See
- \PEAR2\Net\RouterOS\setQuery()


__invoke(mixed $arg = null) : mixed
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.
Name | Type | Description |
---|---|---|
$arg | mixed | A {@link Query} to associate the request with, a {@link Communicator} to send the request over, an argument to get the value of, or NULL to get all arguments as an array. If a second argument is provided, this becomes the name of the argument to set the value of, and the second argument is the value to set. |
Type | Description |
---|---|
mixed | Whatever the long form function would have returned. |


_send(\PEAR2\Net\RouterOS\Communicator $com) : int
Sends a request over a communicator.
The only difference with the non private equivalent is that this one does not do locking.
Name | Type | Description |
---|---|---|
$com | \PEAR2\Net\RouterOS\Communicator | The communicator to send the request over. |
Type | Description |
---|---|
int | The number of bytes sent. |


getAllArguments() : array
Gets all arguments in an array.
Inherited from: \PEAR2\Net\RouterOS\Message::getAllArguments()Type | Description |
---|---|
array | An array with the keys as argument names, and the array values as argument values. |
- See
- \PEAR2\Net\RouterOS\getArgument()
- See
- \PEAR2\Net\RouterOS\setArgument()


getArgument(string $name) : string | resource
Name | Type | Description |
---|---|---|
$name | string | The name of the argument. |
Type | Description |
---|---|
string | resource | The value of the specified argument. Returns NULL if such an argument is not set. |
- See
- \PEAR2\Net\RouterOS\setArgument()


getCommand() : string
Gets the command that will be send to RouterOS.
Gets the command that will be send to RouterOS in its API syntax.
Type | Description |
---|---|
string | The command to send. |
- See
- \PEAR2\Net\RouterOS\setCommand()


getQuery() : \PEAR2\Net\RouterOS\Query
Gets the currently associated query
Type | Description |
---|---|
\PEAR2\Net\RouterOS\Query | The currently associated query. |
- See
- \PEAR2\Net\RouterOS\setQuery()


getTag() : string
Gets the tag that the message is associated with.
Inherited from: \PEAR2\Net\RouterOS\Message::getTag()Type | Description |
---|---|
string | The current tag or NULL if there isn't a tag. |
- See
- \PEAR2\Net\RouterOS\setTag()


parseArgumentString(string $string) : void
Parses the arguments of a command.
Name | Type | Description |
---|---|---|
$string | string | The argument string to parse. |


removeAllArguments() : \PEAR2\Net\RouterOS\self | \PEAR2\Net\RouterOS\Request
Removes all arguments from the request.
Type | Description |
---|---|
\PEAR2\Net\RouterOS\self | \PEAR2\Net\RouterOS\Request | The request object. |


sanitizeArgumentName(mixed $name) : string
Sanitizes a name of an argument (message or query one).
Inherited from: \PEAR2\Net\RouterOS\Message::sanitizeArgumentName()Name | Type | Description |
---|---|---|
$name | mixed | The name to sanitize. |
Type | Description |
---|---|
string | The sanitized name. |


sanitizeArgumentValue(mixed $value) : string
Sanitizes a value of an argument (message or query one).
Inherited from: \PEAR2\Net\RouterOS\Message::sanitizeArgumentValue()Name | Type | Description |
---|---|---|
$value | mixed | The value to sanitize. |
Type | Description |
---|---|
string | The sanitized value. |


send(\PEAR2\Net\RouterOS\Communicator $com, \PEAR2\Net\RouterOS\Registry $reg = null) : int
Sends a request over a communicator.
Name | Type | Description |
---|---|---|
$com | \PEAR2\Net\RouterOS\Communicator | The communicator to send the request over. |
$reg | \PEAR2\Net\RouterOS\Registry | An optional registry to sync the request with. |
Type | Description |
---|---|
int | The number of bytes sent. |


setArgument(string $name, string $value = '') : \PEAR2\Net\RouterOS\self | \PEAR2\Net\RouterOS\Request
Sets an argument for the request.
Name | Type | Description |
---|---|---|
$name | string | Name of the argument. |
$value | string | Value of the argument. Setting the value to NULL removes an argument of this name. |
Type | Description |
---|---|
\PEAR2\Net\RouterOS\self | \PEAR2\Net\RouterOS\Request | The request object. |
- See
- \PEAR2\Net\RouterOS\getArgument()


setCommand(string $command) : \PEAR2\Net\RouterOS\self | \PEAR2\Net\RouterOS\Request
Sets the command to send to RouterOS.
Sets the command to send to RouterOS. The command can use the API or CLI syntax of RouterOS, but either way, it must be absolute (begin with a "/") and without arguments.
Name | Type | Description |
---|---|---|
$command | string | The command to send. |
Type | Description |
---|---|
\PEAR2\Net\RouterOS\self | \PEAR2\Net\RouterOS\Request | The request object. |
- See
- \PEAR2\Net\RouterOS\getCommand()
- See
- \PEAR2\Net\RouterOS\setArgument()


setQuery(\PEAR2\Net\RouterOS\Query $query = null) : \PEAR2\Net\RouterOS\self | \PEAR2\Net\RouterOS\Request
Sets the query to send with the command.
Name | Type | Description |
---|---|---|
$query | \PEAR2\Net\RouterOS\Query | The query to be set. Setting NULL will remove the currently associated query. |
Type | Description |
---|---|
\PEAR2\Net\RouterOS\self | \PEAR2\Net\RouterOS\Request | The request object. |
- See
- \PEAR2\Net\RouterOS\getQuery()


setTag(string $tag) : \PEAR2\Net\RouterOS\self | \PEAR2\Net\RouterOS\Request
Sets the tag to associate the request with.
Sets the tag to associate the request with. Setting NULL erases the currently set tag.
Name | Type | Description |
---|---|---|
$tag | string | The tag to set. |
Type | Description |
---|---|
\PEAR2\Net\RouterOS\self | \PEAR2\Net\RouterOS\Request | The request object. |
- See
- \PEAR2\Net\RouterOS\getTag()