Code Monkey home page Code Monkey logo

Comments (2)

boenrobot avatar boenrobot commented on July 30, 2024

All of those requests return responses that contain one !re reply, followed by one !done reply. The !re reply is the one containing the data you want, while the !done is empty.

In your response callback, you're only checking the tag, but never the response type. Combine that with overwriting the previous response entirely (rather than appending it to a collection/array of some sort), and the result now looks obvious - you get 3 !done replies, which don't contain any properties, because all the stuff you actually wanted was at the previous !re reply.

To do what you want, you should either be appending stuff to the respective variables OR (in the case of these menus) you could simply detect the response type, and only replace the old one if it's a !re reply, e.g.

public function notifyDeviceInfo(RouterOS\Response $response) {
    if ($response->getType() === Response::TYPE_DATA) {
        switch ($response->getTag()) {
                case "deviceIdentity":
                    $this->identityResponse = $response;
                    break;
                case "deviceLicense":
                    $this->licenseResponse = $response;
                    break;
                case "deviceRouterboard":
                    $this->routerboardResponse = $response;
                    break;
                case "deviceResource":
                    $this->resourceResponse = $response;
                    break;
        }
    }

or quite frankly, you should also be able to use:

public function notifyDeviceInfo(RouterOS\Response $response) {
    if ($response->getType() === Response::TYPE_DATA) {
        $this->{$response->getTag()} = $response;
    }

if you just adjust your tag names to match the property names or vice versa.

from net_routeros.

FezzFest avatar FezzFest commented on July 30, 2024

Thank you! The code works a treat and thanks to your explanation I see where I've gone wrong :)

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.