Code Monkey home page Code Monkey logo

Comments (4)

boenrobot avatar boenrobot commented on July 30, 2024

The properties in each response are also traversable. i.e. you can do

$plain = [];
/**
 * @var \PEAR2\Net\RouterOS\ResponseCollection $response
 * @var \PEAR2\Net\RouterOS\Response $row
 */
foreach ($response as $i => $row) {
    $plain[$i] = [];
    foreach ($row as $name => $value) {
        $plain[$i][$name] = $value;
    }
}

And with that in mind, I'm not sure I see a good use case for when a plain array is required... In the rare case where it might be needed, you can extract it out of the traversable, e.g.

$plain = [];
/** @var \ArrayObject $iterator */
$iterator = $response[0]->getIterator();
$plain[0] = $iterator->getArrayCopy();

The typical cases where you may need an array, like indexing based on a property value or ordering based on one or more properties are possible with the methods in ResponseCollection.

from net_routeros.

aTanCS avatar aTanCS commented on July 30, 2024

I use plain arrays for saving a result as a json to a DB. And I use it a lot for debugging, when I just need to dump a result. With the current state I can't see a result in a readable format, when I use breakpoints. I have to convert it to an array.

from net_routeros.

boenrobot avatar boenrobot commented on July 30, 2024

Well, I've made 0a8e77c in which I've added __debugInfo() support to answer this request, and also an option in ResponseCollection::toArray() to call it on all responses in the collection.

The JSON serialization is an interesting use case, and my first thought was to use the JsonSerializable interface, but that one would require that the minimum required PHP version is bumped to PHP 5.4. __debugInfo() on the other hand has an effect in PHP 5.6 and later, but can be called like a normal function in all earlier PHP versions.

The upcoming phar will include it, but in the meantime, if you want to try it out now, you can use composer, and specify the version you want as "dev-develop".

from net_routeros.

aTanCS avatar aTanCS commented on July 30, 2024

Thanks a lot!

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.