sigep API returns array with visibility of properties

0

I'm using a Sigep API that I found in github, I did some testing and it 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 noticed this in other libraries / libraries, is this some kind of pattern?

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

return example:

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
                )
    
asked by anonymous 17.02.2018 / 01:17

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 var_dump only to demonstrate the result.

In order to access the data of this object in your site, in a "correct" way, it is enough to 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());
    }
}
    
17.02.2018 / 01:28