Whoa, so much things to clear up... I'm so sorry for having to do this...
require_once 'PEAR2_Net_Transmitter-1.0.0a5.phar';
require_once 'PEAR2_Net_RouterOS-1.0.0b5.phar';
The 'PEAR2_Net_RouterOS-1.0.0b5.phar' file includes everything from PEAR2_Net_Transmitter. No need to include them both.
Edit: I removed
if ($response->getType() === Response::TYPE_DATA) {
from the code and it seems to work now. Is this Response check necessary? If I look through the wiki on Github then it is actually used a lot.
The value of Response::getType() is one of !re, !done, !trap or !fatal - whichever one the returned API sentence has. The check is done because often you don't want to actually "do" anything with the !done reply. Instead, that reply is returned merely as a "we're done here" marker, with no useful data added to it. Other times however, you do actually want to do something with a !done reply, especially if it has some data in it, rather than this data being part of a previous !re reply. Case in point is the "ret" argument on "add" commands. So to address such cases, it's up to you to check if the response is one you want to deal with for your particular case.
And if you're thinking that sounds like a pretty edge case that doesn't justify the added complexity, and that in 99% all you need is CRUD operations, with the "Read" part being over the actual data... That's what the Util class, and its getAll() method are for - to make that common case trivial to pull off.
Right now this is my work-around:
if ($response->getType() != '!done') { // statements }
This is as perfectly valid and fine as using constants.
The purpose of the constants is to better assist you when using IDEs, as it's easier for them to find instances of a constant being used than it is to find a string used in a particular type of context (e.g. the string "!done" used for a response type vs. a typo in a longer text that should've been a sentence ending with "!", and the first word of the next sentence being "done", but someone forgot the space between the two), plus it enables the PHP compilers (think Hack, not the interpreter...) to do some minor optimizations.
define('TYPE_DATA', '!re');
define('TYPE_FINAL', '!done');
define('TYPE_ERROR', '!trap');
define('TYPE_FATAL', '!fatal');
The "real" constants are part of the Response class, and these here are global constants. They're unnecessary, and only pollute your global namespace.
You can simply replace "Response::TYPE_DATA" with "RouterOS\Response::TYPE_DATA", and the rest analogously.
The root of the whole problem here is a misunderstanding of how namespaces work... When you have at the top
namespace PEAR2\Net\RouterOS;
everything else is relative to that namespace, so when you use
you're referring to the "\PEAR2\Net\RouterOS\Client" class, and similarly, when you have
if ($response->getType() === Response::TYPE_DATA) {
you're reffering to the "TYPE_DATA" constant that's inside the "\PEAR2\Net\RouterOS\Response" class.
On other hand, if at the top you have
everything is still relative to whatever "namespace" says (or is not relative to a namespace, if "namespace" is not present at all). Everything EXCEPT the part that's last in there - RouterOS. Everything that starts with "RouterOS", followed by "\" is instead relative to "\PEAR2\Net\RouterOS". Therefore,
and
if ($response->getType() === RouterOS\Response::TYPE_DATA) {
would target the same classes as before, while
would be looking for a class named "Client" at the root namespace (which doesn't exist), and same with "Response".
$monitor = new RouterOS\Request('/interface/ethernet/monitor=once=10');
> sigh <
I suggest you read
this particular section of the GitHub wiki, but to save you the trouble of reading more than you've already did (speaking of which, if you've read all of this post so far, thank you), you can also do it with
$monitor = new RouterOS\Request('/interface ethernet monitor numbers=ether10 once');
(replacing "ether10" with the actual name of the interface you want to monitor, because the API protocol doesn't support numbers, despite the argument name being "numbers")