Skip to content

Commit aa5d741

Browse files
committed
Doc fixes;
Added support for associative arrays at Util::escapeValue(); Adjusted the console's decoded length column to be 11 characters - the maximum protocol supported length (as opposed to the maximum RouterOS supported length).
1 parent 68a0459 commit aa5d741

File tree

6 files changed

+71
-65
lines changed

6 files changed

+71
-65
lines changed

bin/roscon.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@
207207
$c_sep = ' | ';
208208
$c_columns = array(
209209
'mode' => 4,
210-
'length' => 10,
210+
'length' => 11,
211211
'encodedLength' => 12
212212
);
213213
$c_columns['contents'] = $cmd->options['size'] - 1//row length
@@ -319,11 +319,8 @@
319319
);
320320
}
321321

322-
$dislayedLength = $length > 9999999999
323-
? '0x' . strtoupper(dechex($length))
324-
: $length;
325322
$details = str_pad(
326-
$dislayedLength,
323+
$length,
327324
$c_columns['length'],
328325
' ',
329326
STR_PAD_LEFT

src/PEAR2/Net/RouterOS/Client.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@
4444
class Client
4545
{
4646
/**
47-
* Used in {@link isRequestActive()} to limit search only to requests
48-
* that have a callback.
47+
* Used in {@link static::isRequestActive()} to limit search only to
48+
* requests that have a callback.
4949
*/
5050
const FILTER_CALLBACK = 1;
5151
/**
52-
* Used in {@link isRequestActive()} to limit search only to requests
53-
* that use the buffer.
52+
* Used in {@link static::isRequestActive()} to limit search only to
53+
* requests that use the buffer.
5454
*/
5555
const FILTER_BUFFER = 2;
5656
/**
57-
* Used in {@link isRequestActive()} to indicate no limit in search.
57+
* Used in {@link static::isRequestActive()} to indicate no limit in search.
5858
*/
5959
const FILTER_ALL = 3;
6060

@@ -438,8 +438,9 @@ public function sendSync(Request $request)
438438
*
439439
* @return ResponseCollection A collection of {@link Response} objects that
440440
* haven't been passed to a callback function or previously extracted
441-
* with {@link extractNewResponses()}. Returns an empty collection when
442-
* $tag is set to NULL (responses can still be extracted).
441+
* with {@link static::extractNewResponses()}. Returns an empty
442+
* collection when $tag is set to NULL (responses can still be
443+
* extracted).
443444
*/
444445
public function completeRequest($tag = null)
445446
{
@@ -590,7 +591,7 @@ public function getPendingRequestsCount()
590591
* to the "/cancel" command is highly reccomended, as it also updates the
591592
* counter of pending requests properly. Note that canceling a request also
592593
* removes any responses for it that were not previously extracted with
593-
* {@link extractNewResponses()}.
594+
* {@link static::extractNewResponses()}.
594595
*
595596
* @param string $tag Tag of the request to cancel. Setting NULL will cancel
596597
* all requests.
@@ -692,8 +693,8 @@ public function isStreamingResponses()
692693
* Closes the opened connection, even if it is a persistent one.
693694
*
694695
* Closes the opened connection, even if it is a persistent one. Note that
695-
* {@link extractNewResponses()} can still be used to extract responses
696-
* collected prior to the closing.
696+
* {@link static::extractNewResponses()} can still be used to extract
697+
* responses collected prior to the closing.
697698
*
698699
* @return bool TRUE on success, FALSE on failure.
699700
*/

src/PEAR2/Net/RouterOS/Communicator.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -231,16 +231,16 @@ public static function iconvStream($in_charset, $out_charset, $stream)
231231
* Sets the default charset(s) for new connections.
232232
*
233233
* @param mixed $charset The charset to set. If $charsetType is
234-
* {@link CHARSET_ALL}, you can supply either a string to use for all
235-
* charsets, or an array with the charset types as keys, and the
234+
* {@link self::CHARSET_ALL}, you can supply either a string to use for
235+
* all charsets, or an array with the charset types as keys, and the
236236
* charsets as values.
237237
* @param int $charsetType Which charset to set. Valid values are the
238238
* CHARSET_* constants. Any other value is treated as
239-
* {@link CHARSET_ALL}.
239+
* {@link self::CHARSET_ALL}.
240240
*
241241
* @return string|array The old charset. If $charsetType is
242-
* {@link CHARSET_ALL}, the old values will be returned as an array with
243-
* the types as keys, and charsets as values.
242+
* {@link self::CHARSET_ALL}, the old values will be returned as an
243+
* array with the types as keys, and charsets as values.
244244
* @see setCharset()
245245
*/
246246
public static function setDefaultCharset(
@@ -267,11 +267,11 @@ public static function setDefaultCharset(
267267
*
268268
* @param int $charsetType Which charset to get. Valid values are the
269269
* CHARSET_* constants. Any other value is treated as
270-
* {@link CHARSET_ALL}.
270+
* {@link self::CHARSET_ALL}.
271271
*
272272
* @return string|array The current charset. If $charsetType is
273-
* {@link CHARSET_ALL}, the current values will be returned as an array
274-
* with the types as keys, and charsets as values.
273+
* {@link self::CHARSET_ALL}, the current values will be returned as an
274+
* array with the types as keys, and charsets as values.
275275
* @see setDefaultCharset()
276276
*/
277277
public static function getDefaultCharset($charsetType)
@@ -284,23 +284,23 @@ public static function getDefaultCharset($charsetType)
284284
* Sets the charset(s) for this connection.
285285
*
286286
* Sets the charset(s) for this connection. The specified charset(s) will be
287-
* used for all future words. When sending, {@link CHARSET_LOCAL} is
288-
* converted to {@link CHARSET_REMOTE}, and when receiving,
289-
* {@link CHARSET_REMOTE} is converted to {@link CHARSET_LOCAL}. Setting
290-
* NULL to either charset will disable charset convertion, and data will be
291-
* both sent and received "as is".
287+
* used for all future words. When sending, {@link self::CHARSET_LOCAL} is
288+
* converted to {@link self::CHARSET_REMOTE}, and when receiving,
289+
* {@link self::CHARSET_REMOTE} is converted to {@link self::CHARSET_LOCAL}.
290+
* Setting NULL to either charset will disable charset convertion, and data
291+
* will be both sent and received "as is".
292292
*
293293
* @param mixed $charset The charset to set. If $charsetType is
294-
* {@link CHARSET_ALL}, you can supply either a string to use for all
295-
* charsets, or an array with the charset types as keys, and the
294+
* {@link self::CHARSET_ALL}, you can supply either a string to use for
295+
* all charsets, or an array with the charset types as keys, and the
296296
* charsets as values.
297297
* @param int $charsetType Which charset to set. Valid values are the
298-
* Communicator::CHARSET_* constants. Any other value is treated as
299-
* {@link CHARSET_ALL}.
298+
* CHARSET_* constants. Any other value is treated as
299+
* {@link self::CHARSET_ALL}.
300300
*
301301
* @return string|array The old charset. If $charsetType is
302-
* {@link CHARSET_ALL}, the old values will be returned as an array with
303-
* the types as keys, and charsets as values.
302+
* {@link self::CHARSET_ALL}, the old values will be returned as an
303+
* array with the types as keys, and charsets as values.
304304
* @see setDefaultCharset()
305305
*/
306306
public function setCharset($charset, $charsetType = self::CHARSET_ALL)
@@ -325,11 +325,11 @@ public function setCharset($charset, $charsetType = self::CHARSET_ALL)
325325
*
326326
* @param int $charsetType Which charset to get. Valid values are the
327327
* CHARSET_* constants. Any other value is treated as
328-
* {@link CHARSET_ALL}.
328+
* {@link self::CHARSET_ALL}.
329329
*
330330
* @return string|array The current charset. If $charsetType is
331-
* {@link CHARSET_ALL}, the current values will be returned as an array
332-
* with the types as keys, and charsets as values.
331+
* {@link self::CHARSET_ALL}, the current values will be returned as an
332+
* array with the types as keys, and charsets as values.
333333
* @see getDefaultCharset()
334334
* @see setCharset()
335335
*/

src/PEAR2/Net/RouterOS/Query.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class Query
7171

7272
/**
7373
* This class is not to be instantiated normally, but by static methods
74-
* instead. Use {@link where()} to create an instance of it.
74+
* instead. Use {@link static::where()} to create an instance of it.
7575
*/
7676
private function __construct()
7777
{

src/PEAR2/Net/RouterOS/ResponseCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class ResponseCollection implements ArrayAccess, SeekableIterator, Countable
6565
/**
6666
* @var array An array with all distinct arguments across all
6767
* {@link Response} objects. Created at the first call of
68-
* {@link getArgumentMap()}.
68+
* {@link static::getArgumentMap()}.
6969
*/
7070
protected $argumentMap = null;
7171

src/PEAR2/Net/RouterOS/Util.php

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ class Util implements Countable
7272
* determining the type in the same way RouterOS would determine it for a
7373
* literal.
7474
*
75-
* This method is intended to be the very opposite of {@link escapeValue()}.
76-
* That is, results from that method, if given to this method, should
77-
* produce equivalent results.
75+
* This method is intended to be the very opposite of
76+
* {@link static::escapeValue()}. hat is, results from that method, if
77+
* given to this method, should produce equivalent results.
7878
*
7979
* @param string $value The value to be parsed. Must be a literal of a
80-
* value, e.g. what {@link escapeValue()} will give you.
80+
* value, e.g. what {@link static::escapeValue()} will give you.
8181
*
8282
* @return mixed Depending on RouterOS type detected:
8383
* - "nil" or "nothing" - NULL.
@@ -196,8 +196,12 @@ public static function escapeValue($value)
196196
break;
197197
}
198198
$result = '';
199-
foreach ($value as $val) {
200-
$result .= ';' . static::escapeValue($val);
199+
foreach ($value as $key => $val) {
200+
$result .= ';';
201+
if (!is_int($key)) {
202+
$result .= static::escapeValue($key) . '=';
203+
}
204+
$result .= static::escapeValue($val);
201205
}
202206
$value = '{' . substr($result, 1) . '}';
203207
break;
@@ -332,7 +336,7 @@ public function changeMenu($newMenu = '')
332336
* @param array $params An array of local variables to make available in
333337
* the script. Variable names are array keys, and variable values are
334338
* array values. Array values are automatically processed with
335-
* {@link escapeValue()}.
339+
* {@link static::escapeValue()}.
336340
* Note that the script's (generated) name is always added as the
337341
* variable "_", which you can overwrite from here.
338342
* @param string $policy Allows you to specify a policy the script must
@@ -366,13 +370,13 @@ public function exec(
366370
* cache may end up being out of date. By calling this method right before
367371
* targeting an item with a number, you can ensure number accuracy.
368372
*
369-
* Note that Util's {@link move()} and {@link remove()} methods
370-
* automatically clear the cache before returning, while {@link add()} adds
371-
* the new item's ID to the cache as the next number. A change in the menu
372-
* also clears the cache.
373+
* Note that Util's {@link static::move()} and {@link static::remove()}
374+
* methods automatically clear the cache before returning, while
375+
* {@link static::add()} adds the new item's ID to the cache as the next
376+
* number. A change in the menu also clears the cache.
373377
*
374378
* Note also that the cache is being rebuilt unconditionally every time you
375-
* use {@link find()} with a callback.
379+
* use {@link static::find()} with a callback.
376380
*
377381
* @return $this The Util object itself.
378382
*/
@@ -527,7 +531,8 @@ public function get($number, $value_name)
527531
*
528532
* Zero or more arguments can be specified, each being a criteria.
529533
* If zero arguments are specified, enables all items.
530-
* See {@link find()} for a description of what criteria are accepted.
534+
* See {@link static::find()} for a description of what criteria are
535+
* accepted.
531536
*
532537
* @return ResponseCollection returns the response collection, allowing you
533538
* to inspect errors, if any.
@@ -542,7 +547,8 @@ public function enable()
542547
*
543548
* Zero or more arguments can be specified, each being a criteria.
544549
* If zero arguments are specified, disables all items.
545-
* See {@link find()} for a description of what criteria are accepted.
550+
* See {@link static::find()} for a description of what criteria are
551+
* accepted.
546552
*
547553
* @return ResponseCollection Returns the response collection, allowing you
548554
* to inspect errors, if any.
@@ -557,7 +563,8 @@ public function disable()
557563
*
558564
* Zero or more arguments can be specified, each being a criteria.
559565
* If zero arguments are specified, removes all items.
560-
* See {@link find()} for a description of what criteria are accepted.
566+
* See {@link static::find()} for a description of what criteria are
567+
* accepted.
561568
*
562569
* @return ResponseCollection Returns the response collection, allowing you
563570
* to inspect errors, if any.
@@ -576,7 +583,7 @@ public function remove()
576583
* which match certain criteria.
577584
*
578585
* @param mixed $numbers Targeted items. Can be any criteria accepted by
579-
* {@link find()} or NULL in case the menu is one without items
586+
* {@link static::find()} or NULL in case the menu is one without items
580587
* (e.g. "/system identity").
581588
* @param array $newValues An array with the names of each property to set
582589
* as an array key, and the new value as an array value.
@@ -597,10 +604,10 @@ public function set($numbers, array $newValues)
597604
}
598605

599606
/**
600-
* Alias of {@link set()}
607+
* Alias of {@link static::set()}
601608
*
602609
* @param mixed $numbers Targeted items. Can be any criteria accepted by
603-
* {@link find()}.
610+
* {@link static::find()}.
604611
* @param array $newValues An array with the names of each changed property
605612
* as an array key, and the new value as an array value.
606613
*
@@ -620,7 +627,7 @@ public function edit($numbers, array $newValues)
620627
* reserved word.
621628
*
622629
* @param mixed $numbers Targeted items. Can be any criteria accepted
623-
* by {@link find()}.
630+
* by {@link static::find()}.
624631
* @param string $value_name The name of the value you want to unset.
625632
*
626633
* @return ResponseCollection Returns the response collection, allowing you
@@ -681,11 +688,11 @@ public function add(array $values)
681688
* be a move command on that menu. If in doubt, check from a terminal.
682689
*
683690
* @param mixed $numbers Targeted items. Can be any criteria accepted
684-
* by {@link find()}.
691+
* by {@link static::find()}.
685692
* @param mixed $destination item before which the targeted items will be
686-
* moved to. Can be any criteria accepted by {@link find()}. If multiple
687-
* items match the criteria, the targeted items will move above the
688-
* first match.
693+
* moved to. Can be any criteria accepted by {@link static::find()}.
694+
* If multiple items match the criteria, the targeted items will move
695+
* above the first match.
689696
*
690697
* @return ResponseCollection Returns the response collection, allowing you
691698
* to inspect errors, if any.
@@ -708,8 +715,8 @@ public function move($numbers, $destination)
708715
*
709716
* Counts items at the current menu. This executes a dedicated command
710717
* ("print" with a "count-only" argument) on RouterOS, which is why only
711-
* queries are allowed as a criteria, in contrast with {@link find()},
712-
* where numbers and callbacks are allowed also.
718+
* queries are allowed as a criteria, in contrast with
719+
* {@link static::find()}, where numbers and callbacks are allowed also.
713720
*
714721
* @param Query $query A query to filter items by. Without it, all items
715722
* are included in the count.
@@ -849,7 +856,8 @@ public function fileGetContents($filename, $tmpScriptName = null)
849856
* @param string $what What action to perform.
850857
* @param array $args Zero or more arguments can be specified, each being
851858
* a criteria. If zero arguments are specified, removes all items.
852-
* See {@link find()} for a description of what criteria are accepted.
859+
* See {@link static::find()} for a description of what criteria are
860+
* accepted.
853861
*
854862
* @return ResponseCollection Returns the response collection, allowing you
855863
* to inspect errors, if any.

0 commit comments

Comments
 (0)