Sigep API returns array with visibility of properties

Asked

Viewed 48 times

0

I’m using a API by Sigep that I found on github, did some tests and worked, the problem is that I would like to return the results in JSON or XML, and the return of the class is coming with the visibility of its properties, I’ve noticed this in other libraries/Ibraries, this is some kind of pattern?

The example used was the "calcPrecoPrazo", inside the examples/calcPrecoPrazo.php folder

example of return:

Array
(
    [*isSoapFault] => 
    [*errorCode] => 
    [*errorMsg] => 
    [*result] => Array
        (
            [0] => PhpSigep\Model\CalcPrecoPrazoResposta Object
                (
                    [servico:protected] => PhpSigep\Model\ServicoDePostagem Object
                        (
                            [codigo:protected] => 41068
                            [idServico:protected] => 109819
                            [nome:protected] => Pac 41068
                            [_failIfAtributeNotExiste:protected] => 1
                        )

                    [valor:protected] => 15.79
                    [prazoEntrega:protected] => 5
                    [valorMaoPropria:protected] => 0
                    [valorAvisoRecebimento:protected] => 0
                    [valorValorDeclarado:protected] => 0
                    [entregaDomiciliar:protected] => 1
                    [entregaSabado:protected] => 
                    [erroCodigo:protected] => 0
                    [erroMsg:protected] => 
                    [_failIfAtributeNotExiste:protected] => 1
                )

1 answer

0

It is not returning the object with its properties. It is returning a value that can be txt, json, xml etc..

But their code converts this result to the object PhpSigep\Model\CalcPrecoPrazoResposta and uses the var_dump only to demonstrate the result.

To access the data of this object on your site, in a "correct" way, just invoke some method with the prefix get. Ex:

<?php

if (isset($response["result"]) && is_array($response["result"])) {
    foreach($response["result"] as $result) {
        echo sprintf("Serviço: %s <br>", $result->getServico());
        echo sprintf("Serviço: %s <br><br>", $result->getValor());
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.