@@ -35,7 +35,7 @@ class Soap implements iRequestXML
3535 * @param array $header
3636 * @param array $increment
3737 *
38- * @return void|string void = sucesso, string = erro
38+ * @return void|string void = sucesso, string = erro.
3939 */
4040 public function setRequest ($ wsdl , array $ header = null , array $ increment = null )
4141 {
@@ -46,7 +46,7 @@ public function setRequest($wsdl, array $header = null, array $increment = null)
4646 'user_agent ' => 'PHP/SOAP ' ,
4747 'trace ' => 1 ,
4848 'encoding ' => 'UTF-8 ' ,
49- // Corrige um problema onde era retornado o erro: Could not connect to host
49+ /** @internal Corrige um problema onde era retornado o erro: Could not connect to host */
5050 'location ' => substr ($ wsdl , 0 , -5 )
5151 ];
5252 }
@@ -61,14 +61,14 @@ public function setRequest($wsdl, array $header = null, array $increment = null)
6161 return $ e ->getMessage ();
6262 }
6363 }
64-
64+
6565 /**
6666 * Dispara a consulta contra o serviço informado.
67- *
67+ *
6868 * @param string $service
6969 * @param string|array $arguments
7070 *
71- * @return void|string null = sucesso, string = erro
71+ * @return void|string null = sucesso, string = erro.
7272 */
7373 public function doRequest ($ service , $ arguments )
7474 {
@@ -78,21 +78,7 @@ public function doRequest($service, $arguments)
7878 }
7979
8080 if (is_string ($ arguments )) {
81- /* @see http://php.net/manual/pt_BR/function.libxml-use-internal-errors.php */
82- libxml_use_internal_errors (true );
83- $ xml = simplexml_load_string ($ arguments );
84-
85- if ($ xml === false ) {
86- foreach (libxml_get_errors () as $ error ) {
87- throw new Exception ('Ocorreu um erro ao processar o XML de envio: ' . $ error ->message );
88- }
89- }
90-
91- if ($ xml = $ xml ->children ('soapenv ' , true )) {
92- $ arguments = $ xml ->Body ->children ()->asXML ();
93- }
94-
95- $ arguments = [new SoapVar ($ arguments , XSD_ANYXML )];
81+ $ arguments = [$ this ->xmlToArray ($ arguments )];
9682 }
9783
9884 $ this ->client ->__soapCall ($ service , $ arguments );
@@ -104,25 +90,20 @@ public function doRequest($service, $arguments)
10490 /**
10591 * Retorna o cabeçalho HTTP da resposta enviada pelo webservice.
10692 *
107- * @param bool $nl2br
108- *
10993 * @return null|string
11094 */
111- public function getHeader ($ nl2br = true )
95+ public function getHeader ()
11296 {
11397 if ($ this ->client ) {
114- $ responseHeader = $ this ->client ->__getLastResponseHeaders ();
115-
116- /* @see http://php.net/manual/pt_BR/function.nl2br.php Documentação para a função nlb2br */
117- return ($ nl2br ) ? nl2br ($ responseHeader ) : $ responseHeader ;
98+ return $ this ->client ->__getLastResponseHeaders ();
11899 }
119100
120101 return null ;
121102 }
122103
123104 /**
124105 * Retorna os métodos expostos pelo WSDL.
125- *
106+ *
126107 * @return array|void
127108 */
128109 public function getMethods ()
@@ -139,8 +120,8 @@ public function getMethods()
139120
140121 /**
141122 * Retorna o XML enviado.
142- *
143- * @return string|null Em caso de sucesso retorna string, para erro retorna null
123+ *
124+ * @return string|null Em caso de sucesso retorna string, para erro retorna null.
144125 */
145126 public function getRequest ()
146127 {
@@ -149,11 +130,39 @@ public function getRequest()
149130
150131 /**
151132 * Retorna o XML recebido.
152- *
153- * @return string|null Em caso de sucesso retorna string, para erro retorna null
133+ *
134+ * @return string|null Em caso de sucesso retorna string, para erro retorna null.
154135 */
155136 public function getResponse ()
156137 {
157138 return ($ this ->client ) ? $ this ->client ->__getLastResponse () : null ;
158139 }
140+
141+ /**
142+ * Transforma a string XML em um objeto \SoapVar.
143+ *
144+ * @param string $arguments
145+ *
146+ * @throws \Exception Dispara uma exception caso ocorra algum erro no processamento da string xml
147+ *
148+ * @return \SoapVar|null
149+ */
150+ public function xmlToArray ($ arguments )
151+ {
152+ /* @see http://php.net/manual/pt_BR/function.libxml-use-internal-errors.php */
153+ libxml_use_internal_errors (true );
154+ $ xml = simplexml_load_string ($ arguments );
155+
156+ if ($ xml === false ) {
157+ foreach (libxml_get_errors () as $ error ) {
158+ throw new Exception ('Ocorreu um erro ao processar o XML de envio: ' . $ error ->message );
159+ }
160+ }
161+
162+ if ($ xml = $ xml ->children ('soapenv ' , true )) {
163+ $ arguments = $ xml ->Body ->children ()->asXML ();
164+ }
165+
166+ return new SoapVar ($ arguments , XSD_ANYXML );
167+ }
159168}
0 commit comments