Skip to content

Commit 0a8f8b9

Browse files
committed
Made Util::getAll() prohibit "follow" and "follow-only" as arguments, and throw NotSupportedException if provided;
Added serial port to Qemu VM; Fixed ApiGen's config file to work with the latest version.
1 parent 9f76038 commit 0a8f8b9

File tree

7 files changed

+51
-21
lines changed

7 files changed

+51
-21
lines changed

docs/apigen.neon

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
source: ../src
1+
title: PEAR2_Net_RouterOS documentation
2+
3+
source:
4+
- ../src
25

36
destination: Reference/ApiGen/Doc
47

5-
extensions: php
8+
extensions:
9+
- php
610

7-
charset: UTF-8
11+
charset:
12+
- UTF-8
813

9-
title: PEAR2_Net_RouterOS documentation
14+
accessLevels:
15+
- public
1016

11-
autocomplete:
12-
- classes
13-
- methods
14-
- classconstants
17+
tree: true

docs/sami.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
->files()
99
->name('*.php')
1010
->exclude('docs')
11-
->exclude('examples')
1211
->exclude('tests')
12+
->exclude('examples')
1313
->in($dir = dirname(__DIR__)),
1414
array(
1515
'title' => 'PEAR2_Net_RouterOS documentation',

src/PEAR2/Net/RouterOS/NotSupportedException.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ class NotSupportedException extends E implements Exception
3939
{
4040

4141
const CODE_CONTROL_BYTE = 1601;
42-
43-
const CODE_MENU_MISMATCH = 60000;
42+
43+
const CODE_MENU_MISMATCH = 60000;
44+
45+
const CODE_ARG_PROHIBITED = 60001;
4446

4547
/**
4648
* @var mixed The unsupported value.

src/PEAR2/Net/RouterOS/Util.php

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class Util implements Countable
7979
* literal.
8080
*
8181
* This method is intended to be the very opposite of
82-
* {@link static::escapeValue()}. hat is, results from that method, if
82+
* {@link static::escapeValue()}. That is, results from that method, if
8383
* given to this method, should produce equivalent results.
8484
*
8585
* @param string $value The value to be parsed. Must be a literal of a
@@ -459,21 +459,27 @@ public function setMenu($newMenu)
459459

460460
/**
461461
* Creates a Request object.
462-
*
463-
* Creates a {@link Request} object, with a command that's relative to the
462+
*
463+
* Creates a {@link Request} object, with a command that's at the
464464
* current menu. The request can then be sent using {@link Client}.
465-
*
465+
*
466466
* @param string $command The command of the request, not including
467467
* the menu. The request will have that command at the current menu.
468468
* @param array $args Arguments of the request.
469-
* Follows the same rules as with {@link Util::getAll()}.
469+
* Each array key is the name of the argument, and each array value is
470+
* the value of the argument to be passed.
471+
* Arguments without a value (i.e. empty arguments) can also be
472+
* specified using a numeric key, and the name of the argument as the
473+
* array value.
470474
* @param Query|null $query The {@link Query} of the request.
471475
* @param string|null $tag The tag of the request.
472-
*
476+
*
473477
* @return Request The {@link Request} object.
474-
*
478+
*
475479
* @throws NotSupportedException On an attempt to call a command in a
476-
* different menu.
480+
* different menu using API syntax.
481+
* @throws InvalidArgumentException On an attempt to call a command in a
482+
* different menu using CLI syntax.
477483
*/
478484
public function newRequest(
479485
$command,
@@ -1015,13 +1021,21 @@ public function count($mode = COUNT_NORMAL, Query $query = null)
10151021
* Arguments without a value (i.e. empty arguments) can also be
10161022
* specified using a numeric key, and the name of the argument as the
10171023
* array value.
1024+
* The "follow" and "follow-only" arguments are prohibited,
1025+
* as they would cause a synchronous request to run forever, without
1026+
* allowing the results to be observed.
1027+
* If you need to use those arguments, use {@link static::newRequest()},
1028+
* and pass the resulting {@link Request} to {@link Client::sendAsync()}.
10181029
* @param Query|null $query A query to
10191030
* filter items by.
10201031
* NULL to get all items.
10211032
*
10221033
* @return ResponseCollection|false A response collection with all
10231034
* {@link Response::TYPE_DATA} responses. The collection will be empty
10241035
* when there are no matching items. FALSE on failure.
1036+
*
1037+
* @throws NotSupportedException If $args contains prohibited arguments
1038+
* ("follow" or "follow-only").
10251039
*/
10261040
public function getAll(array $args = array(), Query $query = null)
10271041
{
@@ -1033,6 +1047,14 @@ public function getAll(array $args = array(), Query $query = null)
10331047
$printRequest->setArgument($name, $value);
10341048
}
10351049
}
1050+
if ($printRequest->getArgument('follow') !== null
1051+
|| $printRequest->getArgument('follow-only') !== null
1052+
) {
1053+
throw new NotSupportedException(
1054+
'The "follow" and "follow-only" arguments are prohibited',
1055+
NotSupportedException::CODE_ARG_PROHIBITED
1056+
);
1057+
}
10361058
$responses = $this->client->sendSync($printRequest);
10371059

10381060
if (count($responses->getAllOfType(Response::TYPE_ERROR)) > 0) {

tests/vm/RouterOS.packer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@
9191
["-device", "virtio-net,netdev=user.1,mac=DE:AD:BE:EF:00:02"],
9292
["-netdev", "user,id=user.2"],
9393
["-device", "virtio-net,netdev=user.2,mac=DE:AD:BE:EF:00:03"],
94+
["-chardev", "null,id=con0"],
95+
["-device", "virtio-serial"],
96+
["-device", "virtserialport,chardev=con0"],
9497
["-m", "128M"]
9598
],
9699
"format": "raw"

tests/vm/RouterOS.qemu.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
:: TODO: Find a way to have the equivalent of VirtualBox's "host-only adapter",
22
:: allowing separate IP addresses, so that the host could access the same ports,
33
:: once on its own IP, and then those ports on the guest's IP.
4-
qemu-system-x86_64 "output-qemu\RouterOS-%ROS_VERSION%.raw" "-name" "RouterOS-%ROS_VERSION%" "-display" "sdl" "-machine" "type=pc,accel=tcg" "-netdev" "user,id=user.0,net=192.168.56.0/24,host=192.168.56.2,dhcpstart=192.168.56.101,hostfwd=tcp::38728-:8728" "-device" "virtio-net,netdev=user.0,mac=DE:AD:BE:EF:00:01" "-netdev" "user,id=user.1" "-device" "virtio-net,netdev=user.1,mac=DE:AD:BE:EF:00:02" "-netdev" "user,id=user.2" "-device" "virtio-net,netdev=user.2,mac=DE:AD:BE:EF:00:03" "-m" "128M"
4+
qemu-system-x86_64 "output-qemu\RouterOS-%ROS_VERSION%.raw" "-name" "RouterOS-%ROS_VERSION%" "-display" "sdl" "-machine" "type=pc,accel=tcg" "-netdev" "user,id=user.0,net=192.168.56.0/24,host=192.168.56.2,dhcpstart=192.168.56.101,hostfwd=tcp::38728-:8728" "-device" "virtio-net,netdev=user.0,mac=DE:AD:BE:EF:00:01" "-netdev" "user,id=user.1" "-device" "virtio-net,netdev=user.1,mac=DE:AD:BE:EF:00:02" "-netdev" "user,id=user.2" "-device" "virtio-net,netdev=user.2,mac=DE:AD:BE:EF:00:03" "-chardev" "null,id=con0" "-device" "virtio-serial" "-device" "virtserialport,chardev=con0" "-m" "128M"

tests/vm/RouterOS.qemu.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# TODO: Find a way to have the equivalent of VirtualBox's "host-only adapter",
33
# allowing separate IP addresses, so that the host could access the same ports,
44
# once on its own IP, and then those ports on the guest's IP.
5-
qemu-system-x86_64 "output-qemu/RouterOS-${ROS_VERSION}.raw" "-name" "RouterOS-${ROS_VERSION}" "-display" "sdl" "-machine" "type=pc,accel=tcg" "-netdev" "user,id=user.0,net=192.168.56.0/24,host=192.168.56.2,dhcpstart=192.168.56.101,hostfwd=tcp::38728-:8728" "-device" "virtio-net,netdev=user.0,mac=DE:AD:BE:EF:00:01" "-netdev" "user,id=user.1" "-device" "virtio-net,netdev=user.1,mac=DE:AD:BE:EF:00:02" "-netdev" "user,id=user.2" "-device" "virtio-net,netdev=user.2,mac=DE:AD:BE:EF:00:03" "-m" "128M"
5+
qemu-system-x86_64 "output-qemu/RouterOS-${ROS_VERSION}.raw" "-name" "RouterOS-${ROS_VERSION}" "-display" "sdl" "-machine" "type=pc,accel=tcg" "-netdev" "user,id=user.0,net=192.168.56.0/24,host=192.168.56.2,dhcpstart=192.168.56.101,hostfwd=tcp::38728-:8728" "-device" "virtio-net,netdev=user.0,mac=DE:AD:BE:EF:00:01" "-netdev" "user,id=user.1" "-device" "virtio-net,netdev=user.1,mac=DE:AD:BE:EF:00:02" "-netdev" "user,id=user.2" "-device" "virtio-net,netdev=user.2,mac=DE:AD:BE:EF:00:03" "-chardev" "null,id=con0" "-device" "virtio-serial" "-device" "virtserialport,chardev=con0" "-m" "128M"

0 commit comments

Comments
 (0)