Util.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\Util
- Author
- Vasil Rangelov
- Category
- Net
- License
- LGPL License 2.1
- Link
- http://pear2.php.net/PEAR2_Net_RouterOS
Properties


array $idCache = null
An array with the numbers of entries in the current menu as keys, and the corresponding IDs as values.
null
Details- Type
- array
Methods


__construct(\PEAR2\Net\RouterOS\Client $client) : void
Creates a new Util instance.
Name | Type | Description |
---|---|---|
$client | \PEAR2\Net\RouterOS\Client | The connection to wrap around. |


_escapeCharacters(string $chars) : string
Escapes a character for a RouterOS scripting context.
Name | Type | Description |
---|---|---|
$chars | string | The matches array, expected to contain exactly one member, in which is the whole string to be escaped. |
Type | Description |
---|---|
string | The escaped character. |


_exec(string $source, array $params = array(), string $policy = null, string $name = null, bool $get = false) : \PEAR2\Net\RouterOS\ResponseCollection | string
Executes a RouterOS script.
Name | Type | Description |
---|---|---|
$source | string | A script to execute. |
$params | array | An array of local variables to make available in the script. Variable names are array keys, and variable values are array values. Note that the script's (generated) name is always added as the variable "_", which you can overwrite from here. Native PHP types will be converted to their RouterOS equivalents. DateTime and DateInterval objects will be casted to RouterOS' "time" type. Other types are casted to strings. |
$policy | string | Allows you to specify a policy the script must follow. Has the same format as in terminal. If left NULL, the script has no restrictions. |
$name | string | The script is executed after being saved in "/system script" under a random name (prefixed with the computer's name), and is removed after execution. To eliminate any possibility of name clashes, you can specify your own name. |
$get | bool | Whether to keep the script after execution. |
Type | Description |
---|---|
\PEAR2\Net\RouterOS\ResponseCollection | string | If the script was not added successfully before execution, the ResponseCollection from the add attempt is going to be returned. Otherwise, the (generated) name of the script. |


add(array $values) : string
Adds a new entry at the current menu.
Name | Type | Description |
---|---|---|
$values | array | Accepts one or more entries to add to the current menu. The data about each entry is specified as an array with the names of each property as an array key, and the value as an array value. |
Type | Description |
---|---|
string | A comma separated list of the new entries' IDs. |


changeMenu(string $newMenu = '') : string
Changes the current menu.
Name | Type | Description |
---|---|---|
$newMenu | string | The menu to change to. Can be specified with API or CLI syntax and can be either absolute or relative. If relative, it's relative to the current menu, which by default is the root. |
Type | Description |
---|---|
string | The old menu. If an empty string is given for a new menu, no change is performed, and this function returns the current menu. |


clearIdCache() : \PEAR2\Net\RouterOS\Util
Clears the ID cache.
Type | Description |
---|---|
\PEAR2\Net\RouterOS\Util | The Util object itself. |
- Fluent
- This method is part of a fluent interface and will return the same instance


disable() : \PEAR2\Net\RouterOS\ResponseCollection
Disables all entries at the current menu matching certain criteria.
Type | Description |
---|---|
\PEAR2\Net\RouterOS\ResponseCollection | returns the response collection, allowing you to inspect errors, if any. |


doBulk(string $what, array $args = array()) : \PEAR2\Net\RouterOS\ResponseCollection
Performs an action on a bulk of entries at the current menu.
Name | Type | Description |
---|---|---|
$what | string | What action to perform. |
$args | array | Zero or more arguments can be specified, each being a criteria. If zero arguments are specified, removes all entries. See {@link find()} for a description of what criteria are accepted. |
Type | Description |
---|---|
\PEAR2\Net\RouterOS\ResponseCollection | returns the response collection, allowing you to inspect errors, if any. |


edit(mixed $numbers, array $newValues) : \PEAR2\Net\RouterOS\ResponseCollection
Alias of {@link set()}
Name | Type | Description |
---|---|---|
$numbers | mixed | Targeted entries. Can be any criteria accepted by {@link find()}. |
$newValues | array | An array with the names of each changed property as an array key, and the new value as an array value. |
Type | Description |
---|---|
\PEAR2\Net\RouterOS\ResponseCollection | returns the response collection, allowing you to inspect errors, if any. |


enable() : \PEAR2\Net\RouterOS\ResponseCollection
Enables all entries at the current menu matching certain criteria.
Type | Description |
---|---|
\PEAR2\Net\RouterOS\ResponseCollection | returns the response collection, allowing you to inspect errors, if any. |


escapeString(string $value) : string
Escapes a string for a RouterOS scripting context.
Name | Type | Description |
---|---|---|
$value | string | Value to be escaped. |
Type | Description |
---|---|
string | The escaped value. |


escapeValue(mixed $value) : string
Escapes a value for a RouterOS scripting context.
Name | Type | Description |
---|---|---|
$value | mixed | The value to be escaped. |
Type | Description |
---|---|
string | A string representation that can be directly inserted in a script as a whole value. |


exec(string $source, array $params = array(), string $policy = null, string $name = null) : \PEAR2\Net\RouterOS\ResponseCollection
Executes a RouterOS script.
Name | Type | Description |
---|---|---|
$source | string | A script to execute. |
$params | array | An array of local variables to make available in the script. Variable names are array keys, and variable values are array values. Array values are automatically processed with {@link escapeValue()}. Note that the script's (generated) name is always added as the variable "_", which you can overwrite from here. |
$policy | string | Allows you to specify a policy the script must follow. Has the same format as in terminal. If left NULL, the script has no restrictions. |
$name | string | The script is executed after being saved in "/system script" under a random name (prefixed with the computer's name), and is removed after execution. To eliminate any possibility of name clashes, you can specify your own name. |
Type | Description |
---|---|
\PEAR2\Net\RouterOS\ResponseCollection | returns the response collection of the run, allowing you to inspect errors, if any. If the script was not added successfully before execution, the ResponseCollection from the add attempt is going to be returned. |


fileGetContents(string $filename, string $tmpScriptName = null) : string | bool
Gets the contents of a specified file.
Name | Type | Description |
---|---|---|
$filename | string | The name of the file to get the contents of. |
$tmpScriptName | string | In order to get the file's contents, a script is created at "/system script" with a random name, the source of which is then overwriten with the file's contents, and finally retrieved. To eliminate any possibility of name clashes, you can specify your own name for the script. |
Type | Description |
---|---|
string | bool | The contents of the file or FALSE if there is no such file. |


filePutContents(string $filename, string $data, bool $overwrite = false) : bool
Puts a file on RouterOS's file system.
Name | Type | Description |
---|---|---|
$filename | string | The filename to write data in. |
$data | string | The data the file is going to have. |
$overwrite | bool | Whether to overwrite the file if it exists. |
Type | Description |
---|---|
bool | TRUE on success, FALSE on failure. |


find() : string
Finds the IDs of entries at the current menu.
Type | Description |
---|---|
string | A comma separated list of all entries matching the specified criteria. |


get(int | string | null $number, string $value_name) : string | null | bool
Gets a value of a specified entry at the current menu.
Name | Type | Description |
---|---|---|
$number | int | string | null | A number identifying the entry you're targeting. Can also be an ID or (in some menus) name. For menus where there are no entries (e.g. "/system identity"), you can specify NULL. |
$value_name | string | The name of the value you want to get. |
Type | Description |
---|---|
string | null | bool | The value of the specified property. If the property is not set, NULL will be returned. If no such entry exists, FALSE will be returned. |


move(mixed $numbers, mixed $destination) : \PEAR2\Net\RouterOS\ResponseCollection
Moves entries at the current menu before a certain other entry.
Name | Type | Description |
---|---|---|
$numbers | mixed | Targeted entries. Can be any criteria accepted by {@link find()}. |
$destination | mixed | Entry before which the targeted entries will be moved to. Can be any criteria accepted by {@link find()}. If multiple entries match the criteria, the targeted entries will move above the first match. |
Type | Description |
---|---|
\PEAR2\Net\RouterOS\ResponseCollection | returns the response collection, allowing you to inspect errors, if any. |


parseValue(string $value) : mixed
Parses a value from a RouterOS scripting context.
Name | Type | Description |
---|---|---|
$value | string | The value to be parsed. Must be a literal of a value, e.g. what {@link escapeValue()} will give you. |
Type | Description |
---|---|
mixed | Depending on RouterOS type detected: - "nil" or "nothing" - NULL. - "number" - int or double for large values. - "bool" - a boolean. - "time" - a {@link DateInterval} object. - "array" - an array, with the values processed recursively. - "str" - a string. - Unrecognized type - treated as an unquoted string. |


remove() : \PEAR2\Net\RouterOS\ResponseCollection
Removes all entries at the current menu matching certain criteria.
Type | Description |
---|---|
\PEAR2\Net\RouterOS\ResponseCollection | returns the response collection, allowing you to inspect errors, if any. |


set(mixed $numbers, array $newValues) : \PEAR2\Net\RouterOS\ResponseCollection
Sets new values.
Name | Type | Description |
---|---|---|
$numbers | mixed | Targeted entries. Can be any criteria accepted by {@link find()} or NULL in case the menu is one without entries (e.g. "/system identity"). |
$newValues | array | An array with the names of each property to set as an array key, and the new value as an array value. |
Type | Description |
---|---|
\PEAR2\Net\RouterOS\ResponseCollection | returns the response collection, allowing you to inspect errors, if any. |


unsetValue(mixed $numbers, string $value_name) : \PEAR2\Net\RouterOS\ResponseCollection
Unsets a value of a specified entry at the current menu.
Name | Type | Description |
---|---|---|
$numbers | mixed | Targeted entries. Can be any criteria accepted by {@link find()}. |
$value_name | string | The name of the value you want to unset. |
Type | Description |
---|---|
\PEAR2\Net\RouterOS\ResponseCollection |