@@ -128,14 +128,19 @@ public function setMenu($newMenu)
128
128
} else {
129
129
$ newMenu = substr (
130
130
$ menuRequest ->setCommand (
131
- '/ ' . str_replace ('/ ' , ' ' , substr ($ this ->menu , 1 )) .
132
- ' ' . str_replace ('/ ' , ' ' , $ newMenu ) . ' ? '
131
+ '/ ' .
132
+ str_replace ('/ ' , ' ' , (string )substr ($ this ->menu , 1 )) .
133
+ ' ' .
134
+ str_replace ('/ ' , ' ' , $ newMenu )
135
+ . ' ? '
133
136
)->getCommand (),
134
137
1 ,
135
138
-2 /*strlen('/?')*/
136
139
);
137
140
if ('' !== $ newMenu ) {
138
141
$ this ->menu = '/ ' . $ newMenu ;
142
+ } else {
143
+ $ this ->menu = '' ;
139
144
}
140
145
}
141
146
}
@@ -598,12 +603,24 @@ public function get($number, $valueName = null)
598
603
* See {@link static::find()} for a description of what criteria are
599
604
* accepted.
600
605
*
601
- * @return ResponseCollection returns the response collection, allowing you
602
- * to inspect errors, if any.
606
+ * @return ResponseCollection Returns the response collection, allowing you
607
+ * to inspect the output. Current RouterOS versions don't return
608
+ * anything useful, but if future ones do, you can read it right away.
609
+ *
610
+ * @throws RouterErrorException When the router returns one or more errors.
603
611
*/
604
612
public function enable ()
605
613
{
606
- return $ this ->doBulk ('enable ' , func_get_args ());
614
+ $ responses = $ this ->doBulk ('enable ' , func_get_args ());
615
+ if (count ($ responses ->getAllOfType (Response::TYPE_ERROR )) > 0 ) {
616
+ throw new RouterErrorException (
617
+ 'Error when enabling items ' ,
618
+ RouterErrorException::CODE_ENABLE_ERROR ,
619
+ null ,
620
+ $ responses
621
+ );
622
+ }
623
+ return $ responses ;
607
624
}
608
625
609
626
/**
@@ -615,11 +632,23 @@ public function enable()
615
632
* accepted.
616
633
*
617
634
* @return ResponseCollection Returns the response collection, allowing you
618
- * to inspect errors, if any.
635
+ * to inspect the output. Current RouterOS versions don't return
636
+ * anything useful, but if future ones do, you can read it right away.
637
+ *
638
+ * @throws RouterErrorException When the router returns one or more errors.
619
639
*/
620
640
public function disable ()
621
641
{
622
- return $ this ->doBulk ('disable ' , func_get_args ());
642
+ $ responses = $ this ->doBulk ('disable ' , func_get_args ());
643
+ if (count ($ responses ->getAllOfType (Response::TYPE_ERROR )) > 0 ) {
644
+ throw new RouterErrorException (
645
+ 'Error when disabling items ' ,
646
+ RouterErrorException::CODE_DISABLE_ERROR ,
647
+ null ,
648
+ $ responses
649
+ );
650
+ }
651
+ return $ responses ;
623
652
}
624
653
625
654
/**
@@ -631,13 +660,24 @@ public function disable()
631
660
* accepted.
632
661
*
633
662
* @return ResponseCollection Returns the response collection, allowing you
634
- * to inspect errors, if any.
663
+ * to inspect the output. Current RouterOS versions don't return
664
+ * anything useful, but if future ones do, you can read it right away.
665
+ *
666
+ * @throws RouterErrorException When the router returns one or more errors.
635
667
*/
636
668
public function remove ()
637
669
{
638
- $ result = $ this ->doBulk ('remove ' , func_get_args ());
670
+ $ responses = $ this ->doBulk ('remove ' , func_get_args ());
639
671
$ this ->clearIdCache ();
640
- return $ result ;
672
+ if (count ($ responses ->getAllOfType (Response::TYPE_ERROR )) > 0 ) {
673
+ throw new RouterErrorException (
674
+ 'Error when removing items ' ,
675
+ RouterErrorException::CODE_REMOVE_ERROR ,
676
+ null ,
677
+ $ responses
678
+ );
679
+ }
680
+ return $ responses ;
641
681
}
642
682
643
683
/**
@@ -661,14 +701,26 @@ public function remove()
661
701
* string.
662
702
*
663
703
* @return ResponseCollection Returns the response collection, allowing you
664
- * to inspect errors, if any.
704
+ * to inspect the output. Current RouterOS versions don't return
705
+ * anything useful, but if future ones do, you can read it right away.
706
+ *
707
+ * @throws RouterErrorException When the router returns one or more errors.
665
708
*/
666
709
public function comment ($ numbers , $ comment )
667
710
{
668
711
$ commentRequest = new Request ($ this ->menu . '/comment ' );
669
712
$ commentRequest ->setArgument ('comment ' , $ comment );
670
713
$ commentRequest ->setArgument ('numbers ' , $ this ->find ($ numbers ));
671
- return $ this ->client ->sendSync ($ commentRequest );
714
+ $ responses = $ this ->client ->sendSync ($ commentRequest );
715
+ if (count ($ responses ->getAllOfType (Response::TYPE_ERROR )) > 0 ) {
716
+ throw new RouterErrorException (
717
+ 'Error when commenting items ' ,
718
+ RouterErrorException::CODE_COMMENT_ERROR ,
719
+ null ,
720
+ $ responses
721
+ );
722
+ }
723
+ return $ responses ;
672
724
}
673
725
674
726
/**
@@ -704,7 +756,16 @@ public function set($numbers, array $newValues)
704
756
if (null !== $ numbers ) {
705
757
$ setRequest ->setArgument ('numbers ' , $ this ->find ($ numbers ));
706
758
}
707
- return $ this ->client ->sendSync ($ setRequest );
759
+ $ responses = $ this ->client ->sendSync ($ setRequest );
760
+ if (count ($ responses ->getAllOfType (Response::TYPE_ERROR )) > 0 ) {
761
+ throw new RouterErrorException (
762
+ 'Error when setting items ' ,
763
+ RouterErrorException::CODE_SET_ERROR ,
764
+ null ,
765
+ $ responses
766
+ );
767
+ }
768
+ return $ responses ;
708
769
}
709
770
710
771
/**
@@ -744,10 +805,19 @@ public function edit($numbers, $valueName, $newValue)
744
805
public function unsetValue ($ numbers , $ valueName )
745
806
{
746
807
$ unsetRequest = new Request ($ this ->menu . '/unset ' );
747
- return $ this ->client ->sendSync (
808
+ $ responses = $ this ->client ->sendSync (
748
809
$ unsetRequest ->setArgument ('numbers ' , $ this ->find ($ numbers ))
749
810
->setArgument ('value-name ' , $ valueName )
750
811
);
812
+ if (count ($ responses ->getAllOfType (Response::TYPE_ERROR )) > 0 ) {
813
+ throw new RouterErrorException (
814
+ 'Error when unsetting value of items ' ,
815
+ RouterErrorException::CODE_UNSET_ERROR ,
816
+ null ,
817
+ $ responses
818
+ );
819
+ }
820
+ return $ responses ;
751
821
}
752
822
753
823
/**
@@ -842,7 +912,16 @@ public function move($numbers, $destination = null)
842
912
$ moveRequest ->setArgument ('destination ' , $ destination );
843
913
}
844
914
$ this ->clearIdCache ();
845
- return $ this ->client ->sendSync ($ moveRequest );
915
+ $ responses = $ this ->client ->sendSync ($ moveRequest );
916
+ if (count ($ responses ->getAllOfType (Response::TYPE_ERROR )) > 0 ) {
917
+ throw new RouterErrorException (
918
+ 'Error when moving items ' ,
919
+ RouterErrorException::CODE_MOVE_ERROR ,
920
+ null ,
921
+ $ responses
922
+ );
923
+ }
924
+ return $ responses ;
846
925
}
847
926
848
927
/**
@@ -1069,18 +1148,19 @@ public function fileGetContents($filename, $tmpScriptName = null)
1069
1148
/**
1070
1149
* Performs an action on a bulk of items at the current menu.
1071
1150
*
1072
- * @param string $what What action to perform.
1073
- * @param array $args Zero or more arguments can be specified, each being
1074
- * a criteria. If zero arguments are specified, removes all items.
1151
+ * @param string $command What command to perform.
1152
+ * @param array $args Zero or more arguments can be specified,
1153
+ * each being a criteria.
1154
+ * If zero arguments are specified, matches all items.
1075
1155
* See {@link static::find()} for a description of what criteria are
1076
1156
* accepted.
1077
1157
*
1078
1158
* @return ResponseCollection Returns the response collection, allowing you
1079
1159
* to inspect errors, if any.
1080
1160
*/
1081
- protected function doBulk ($ what , array $ args = array ())
1161
+ protected function doBulk ($ command , array $ args = array ())
1082
1162
{
1083
- $ bulkRequest = new Request ($ this ->menu . ' / ' . $ what );
1163
+ $ bulkRequest = new Request ("{ $ this ->menu } / { $ command }" );
1084
1164
$ bulkRequest ->setArgument (
1085
1165
'numbers ' ,
1086
1166
call_user_func_array (array ($ this , 'find ' ), $ args )
0 commit comments