Code Monkey home page Code Monkey logo

Comments (4)

boenrobot avatar boenrobot commented on July 30, 2024

You should check that page in the wiki that says "API Reference".

It has detailed information on all methods and classes in the package. In this case, you're asking about Util::getAll() and ResponseCollection.

To answer your specific questions though, you can read a ResponseCollection as if you would read an array - a foreach loop, or a for loop with a count(), and as you can see in the reference, there are also a few extra methods for filtering it and sorting the responses.

Each response in the ResponseCollection, you can also read as if you were reading an associative array (for properties), and there are a few extra methods for accessing things that are not properties (type and tag). So in its simplest form, you can think of a ResponseCollection as an array of associative arrays. e.g.

foreach ($array as $response) {
    foreach ($response as $propName => $propValue) {
        echo 'The property "' . $propName . '" has a value "' . $propValue . '". ';
    }
}

And yes, just as you can use a "where" from a command line, you can use a RouterOS\Query object as the second argument of getAll() to return only items matching a criteria, in this case, all where the MAC address is a certain one, f.e.

$array = $util->setMenu('/ip dhcp-server lease')
    ->getAll(array(), RouterOS\Query::where('mac-address', 'B0:E8:92:30:C9:4D'));

As you can see in the reference, the first argument is extra arguments to pass to the "print" request.

from net_routeros.

brsnik avatar brsnik commented on July 30, 2024

On our company router we have two networks, public and private.

I've connected to both for testing purposes. And when I search by MAC I get the following error:

Fatal error:  Uncaught PEAR2\Net\RouterOS\RouterErrorException: Error getting property in /var/www/.../PEAR2/Net/RouterOS/Util.php:561
Stack trace:
#0 /var/www/.../mtk_test.php(68): PEAR2\Net\RouterOS\Util->get('*2f32*2f57')
#1 {main}
Response collection:
Array
(
    [0] => PEAR2\Net\RouterOS\Response Object
        (
            [unrecognizedWords:protected] => Array
                (
                )

            [_type:PEAR2\Net\RouterOS\Response:private] => !trap
            [attributes:protected] => Array
                (
                    [message] => invalid internal item number
                )

            [_tag:PEAR2\Net\RouterOS\Message:private] => 
        )

    [1] => PEAR2\Net\RouterOS\Response Object
        (
            [unrecognizedWords:protected] => Array
                (
                )

            [_type:PEAR2\Net\RouterOS\Response:private] => !done
            [attributes:protected] => Array
                (
         in /var/www/.../PEAR2/Net/RouterOS/Util.php on line 561

Totally crashes my script.

Is it possible for catch{} to return the message [message] => invalid internal item number?

from net_routeros.

boenrobot avatar boenrobot commented on July 30, 2024

First off, assuming you used Util::find() with a Query (and you then passed the result to Util::get()), the cause is probably this issue. I'll release a new fixed version soon, though if you want it "now", you can use Composer with "dev-develop" as the version of "pear2/net_routeros" to get.

But in general, yes, as the error message itself says, this is an uncaught exception, meaning you can catch it if you want, and deal with it, f.e.

try {
$address = $util->get($util->find(RouterOS\Query::where('mac-address', 'B0:E8:92:30:C9:4D')), 'address');
} catch (RouterOS\RouterErrorException $e) {
echo 'Router message: ' . $e->getResponses()->getAllOfType(RouterOS\Response::TYPE_ERROR)->getProperty('message');
}

from net_routeros.

brsnik avatar brsnik commented on July 30, 2024

Thanks.

Error message is returned this way.
However theres a Notice you might want to look into for the next update.

Notice: Array to string conversion in /var/www/.../PEAR2/Net/RouterOS/Util.php on line 488

from net_routeros.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.