1

I'm using a WebService (WSDL-SOAP) to retrieve some information from a governmental system.

For that, i'm using the "BeSimple" component (https://github.com/BeSimple/BeSimpleSoapClient), to extend the native PHP SoapClient function so it's able to read "XOP/XML" files instead of "Text/XML".

Everything worked just fine.

I'm now having some trouble handling the response, because it returns too many variables/attributes, as i'm going to explain below.

WSDL Response:

stdClass Object ( [sucesso] => 1 [mensagem] => Processo consultado com sucesso [processo] => stdClass Object ( [dadosBasicos] => stdClass Object ( [polo] => Array ( [0] => stdClass Object ( [parte] => Array ( [0] => stdClass Object ( [pessoa] => stdClass Object ( [documento] => Array ( [0] => stdClass Object ( [codigoDocumento] => 541.xxx.xxx-xx [emissorDocumento] => Secretaria da Receita Federal do Brasil [tipoDocumento] => CMF [nome] => ROGERIO XXXXX XXXXX ) [1] => stdClass Object ( [codigoDocumento] => XXXXXXX [tipoDocumento] => CI [nome] => ROGERIO XXXXXXXXXXX ) [2] => stdClass Object ( [codigoDocumento] => XXXXXXXXXX [emissorDocumento] => Justiça Eleitoral [tipoDocumento] => TE [nome] => ROGERIO XXXXXXXXXXXXXXXXXX ) ) [endereco] => Array ( [0] => stdClass Object ( [logradouro] => Rua Santo XXXXXXX [numero] => 245 [complemento] => casa [bairro] => Alvorada [cidade] => CONTAGEM [estado] => MG [cep] => 32042270 ) ) [nome] => ROGERIO GERALDO DA COSTA VALADARES [sexo] => M [nomeGenitora] => ESTER XXXXXXXXXXXXXXXXXX [dataNascimento] => 19651031 [numeroDocumentoPrincipal] => XXXXXXXXXXXXX [tipoPessoa] => fisica [nacionalidade] => BR ) [advogado] => Array ( [0] => stdClass Object ( [nome] => FELIPE MAURICIO SALIBA DE SOUZA [inscricao] => MG0108211A [numeroDocumentoPrincipal] => XXXXXXXXXXXXXXXXXXXX [intimacao] => [tipoRepresentante] => A ) ) [assistenciaJudiciaria] => [intimacaoPendente] => 0 ) ) [polo] => AT ) [1] => stdClass Object ( [parte] => Array ( [0] => stdClass Object ( [pessoa] => stdClass Object ( [documento] => Array ( [0] => stdClass Object ( [codigoDocumento] => 108.383.949.112 [emissorDocumento] => SECRETARIA FAZENDA [tipoDocumento] => RJC [nome] => DAVID ) [1] => stdClass Object ( [codigoDocumento] => 02.558.157/0009-102707200 [emissorDocumento] => Receita Federal [tipoDocumento] => RJC [nome] => Telefônica Brasil S.A ) [2] => stdClass Object ( [codigoDocumento] => XXXXXXXXXXXXXXXXXX [emissorDocumento] => SEF sp [tipoDocumento] => RJC [nome] => VIVO ) [3] => stdClass Object ( [codigoDocumento] => 6110801 [emissorDocumento] => junta comercial [tipoDocumento] => RJC [nome] => cadastro nacional de pessoa jurídica ) [4] => stdClass Object ( [codigoDocumento] => 35.3.0015881-4 [emissorDocumento] => NIRE [tipoDocumento] => RJC [nome] => TELEFÔNICA BRASIL S.A ) [5] => stdClass Object ( [codigoDocumento] => 0621904680045 [emissorDocumento] => JUNTA COMERCIAL [tipoDocumento] => RJC [nome] => TELEFONICA BRASILA S/A ) [6] => stdClass Object ( [codigoDocumento] => 02558157000910 [emissorDocumento] => receita federal do brasil [tipoDocumento] => RJC [nome] => Telefônica Brasil S.A. ) [7] => stdClass Object ( [codigoDocumento] => 14450231/000101 [emissorDocumento] => Ministério do desenvolvimento industrial e Comerci [tipoDocumento] => RJC [nome] => Fabiana Gaião Cunha S/A ) [8] => stdClass Object ( [codigoDocumento] => 02558157000162 [emissorDocumento] => RECEITA FEDERAL DO BRASIL [tipoDocumento] => RJC [nome] => TELEFONICA DO BRASIL SA ) [9] => stdClass Object ( [codigoDocumento] => 02.558.157/001-62 [emissorDocumento] => 02.558.157/001-62 [tipoDocumento] => RJC [nome] => VIVA S.A ) [10] => stdClass Object ( [codigoDocumento] => 062.190468.00-45 [emissorDocumento] => RFB [tipoDocumento] => RJC [nome] => TELEFÔNICA BRASIL S.A ) [11] => stdClass Object ( [codigoDocumento] => 621.904.680.045 [emissorDocumento] => ESTADO DE MINAS GERAIS [tipoDocumento] => RJC [nome] => Telefonica Brasil S.A. ) [12] => stdClass Object ( [codigoDocumento] => 02.558.157/0000-16 [emissorDocumento] => Receita Federal do Brasil [tipoDocumento] => CMF [nome] => TELEFONICA BRASIL S.A. ) [13] => stdClass Object ( [codigoDocumento] => 02558157/0009-10 [emissorDocumento] => RECEITA FEDERAL [tipoDocumento] => RJC [nome] => TELEFONICA BRASIL S.A ) [14] => stdClass Object ( [codigoDocumento] => 02558167000162 [emissorDocumento] => RECEITA FEDERAL [tipoDocumento] => RJC [nome] => - TELEFONICA BRASIL S.A. ) [15] => stdClass Object ( [codigoDocumento] => 108383949112 [emissorDocumento] => Receita Estadual [tipoDocumento] => RJC [nome] => Telefônica Brasil S.A. ) [16] => stdClass Object ( [codigoDocumento] => 35300158814 [emissorDocumento] => nire [tipoDocumento] => RJC [nome] => Telefonica Brasil S/A ) [17] => stdClass Object ( [codigoDocumento] => 621904680045 [emissorDocumento] => Secretaria da Receita Estadual [tipoDocumento] => RJC [nome] => Secretario Receita Estadual ) ) [endereco] => Array ( [0] => stdClass Object ( [logradouro] => RUA LEVINDO LOPES [numero] => 258 [bairro] => SAVASSI [cidade] => BELO HORIZONTE [estado] => MG [cep] => 30140170 ) ) [nome] => TELEFONICA BRASIL S.A. [dataNascimento] => 19980604 [numeroDocumentoPrincipal] => 02558157000016 [tipoPessoa] => juridica ) [advogado] => Array ( [0] => stdClass Object ( [endereco] => Array ( [0] => stdClass Object ( [logradouro] => Avenida Engenheiro Luiz Carlos Berrini, 1376 [numero] => 1376 [complemento] => [bairro] => Cidade Monções [cidade] => SãO PAULO [estado] => SP [cep] => 04571936 ) ) [nome] => LUCIANA PORTELA ANUNCIACAO [inscricao] => MG0106790A [numeroDocumentoPrincipal] => 01284876667 [intimacao] => [tipoRepresentante] => A ) ) [assistenciaJudiciaria] => [intimacaoPendente] => 0 )
$client = new BeSimpleSoapClient('https://pjerecursal.tjmg.jus.br/pje/intercomunicacao?wsdl', $options);

try {
$response = $client->consultarProcesso(array(
                        "idConsultante" => "xxxxxx",
            "senhaConsultante" => "xxxxxx",
            "numeroProcesso" => "5014522-37.2018.8.13.0079",
            "movimentos" => 1
));
print_r($response);

To sum up, I want to know the best way to handle the response I'm getting, so I can isolate some answers.

I don't know how to access each attribute the better way, because the only way I could think is like that:

$response->processo->dadosBasicos->polo['0']->parte['0']->pessoa->nome.

I need some way to make it cleaner, better and more efficient.

Thank you

  • 1
    Hi - it really shouldn't matter to you if the object has 1 or 1000 attributes. Just access what you need. Is there something specific that's giving you trouble? – waterloomatt Sep 05 '19 at 14:02
  • @upgrego answering your question, no. That's public information you can get at the Local Cort Website, just entering the case number. In anyway, I removed the crucial data. – João Pedro Montes Santos Sep 05 '19 at 14:25
  • @waterloomatt Hello waterloomatt, yes, there is. I don't know how to access each attribute the better way, because the only way I could think is like that: $response->processo->dadosBasicos->polo['0']->parte['0']->pessoa->nome I need some way to make it cleaner, better and more efficient. – João Pedro Montes Santos Sep 05 '19 at 14:26
  • That is the right way to do it. You don't really have many options here because the dataset is coming from an external source. Now, you can work with an object (`stdClass`) as you currently are, or you can convert it to an array (`json_decode($response, true)`. Either way, you still have nested data. You can use loops (`foreach`, `for`) to iterate over repetitive nodes. If you find yourself typing `$response->processo->dadosBasicos->polo['0']->parte['0']` over and over again, assign it to a variable and use the variable instead. Maybe someone else has a better idea. – waterloomatt Sep 05 '19 at 15:21
  • Thanks @waterloomatt Unfortunately, it's as I expected. Also, json_decode doesn't work. It requires a string. `Warning: json_decode() expects parameter 1 to be string, object given in /var/www/wstest/besimple.php on line 41 ` – João Pedro Montes Santos Sep 06 '19 at 02:17
  • See here - https://stackoverflow.com/a/18576902/296555 – waterloomatt Sep 06 '19 at 11:53

0 Answers0