The same thing for which Denis’ class is for - to communicate with RouterOS using the MikroTik API.
The difference is mostly in syntax - Denis’ class forces you to read the API specification and make sure you act in accordance with it. What I do instead is to abstract the details away and instead focus on providing more intuitive ways to send requests and deal with responses. The developer is expected only to have basic understanding of RouterOS’ shell syntax (API syntax can still be used of course) and basic understanding of how to use objects in PHP.
Example:
$API = new routeros_api();
$API->debug = false;
if ($API->connect('xxx.xxx.xxx.xxx', 'nukeko', 'wkd4496')) {
$API->write('/ip/hotspot/user/add', array(
"name" => $nombre,
));
}
$API->disconnect();
vs.
<?php
namespace PEAR2\Net\RouterOS;
require_once 'PEAR2/Net/RouterOS/Autoload.php';
$client = new Client('xxx.xxx.xxx.xxx', 'nukeko', 'wkd4496');
//Define $nombre somewhere around or before here
$addRequest = new Request('/ip hotspot user add');
$addRequest->setArgument('name', $nombre);
$client->sendSync($addRequest);
You probably don’t see much difference here. However, where my package shines is in readability of more complex requests.
For example to change the password, with my package you’d do
<?php
namespace PEAR2\Net\RouterOS;
require_once 'PEAR2/Net/RouterOS/Autoload.php';
$client = new Client('xxx.xxx.xxx.xxx', 'nukeko', 'wkd4496');
//Define $nombre and $password somewhere around or before here
$nombreId = $client->sendSync(new Request('/ip hotspot user print .proplist=.id', null, Query::where('name', $nombre)))->getArgument('.id');
if (null === $nombreId) {
echo "'{$nombre}' is not a registered username";
} else {
$setRequest = new Request('/ip hotspot user set');
$client->sendSync(
$setRequest->setArgument('numbers', $nombreId)
->setArgument('password', $password)
);
}
And doing that is a little more complex with Denis’ class. It’s still possible… but IMHO, the above is both shorter and more readable way of doing it.
BTW, if you have PHP 5.4, you can (if you want to) even sqeeze the code above to:
<?php
namespace PEAR2\Net\RouterOS;
require_once 'PEAR2/Net/RouterOS/Autoload.php';
//Define $nombre and $password somewhere around or before here
if (null === $nombreId = ($client = new Client('xxx.xxx.xxx.xxx', 'nukeko', 'wkd4496'))->sendSync(new Request('/ip hotspot user print .proplist=.id', null, Query::where('name', $nombre)))->getArgument('.id')) {
echo "'{$nombre}' is not a registered username";
} else {
$client((new Request('/ip hotspot user set'))->setArgument('numbers', $nombreId)
->setArgument('password', $password)
);
}
It’s not about “why”… it’s about “why not”. 