Skip to content

Commit 2cb1745

Browse files
Melhorias gerais e adequação de padrões
1 parent 00bbcf7 commit 2cb1745

4 files changed

Lines changed: 55 additions & 41 deletions

File tree

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,12 @@ if(!$erro = $obj->doRequest('nomeServico', $args)) {
114114
115115
// Retorna uma string contendo o cabeçalho da resposta http
116116
// Obs: Só retorna valor se doRequest já tiver sido chamado
117-
// $obj->getHeader();
117+
/**
118+
* Retorna uma string contendo o cabeçalho da resposta http do webservice. Deve vir depois de doRequest()
119+
*
120+
* @see http://php.net/manual/pt_BR/function.nl2br.php Documentação para a função nlb2br.
121+
*/
122+
echo nl2br($obj->getHeader());
118123
} else {
119124
echo $erro;
120125
}

src/ClienteGenerico.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ClienteGenerico implements iRequestXML
2121
/**
2222
* Armazena uma instância de Curl.
2323
*
24-
* @var object
24+
* @var resource
2525
*/
2626
private $curl;
2727

@@ -40,14 +40,14 @@ class ClienteGenerico implements iRequestXML
4040
private $info;
4141

4242
/**
43-
* Cabeçalho a ser enviado
43+
* Cabeçalho a ser enviado.
4444
*
4545
* @var array
4646
*/
4747
private $header;
4848

4949
/**
50-
* Conteúdo (xml) bruto a ser enviado
50+
* Conteúdo (xml) bruto a ser enviado.
5151
*
5252
* @var string
5353
*/
@@ -71,9 +71,9 @@ public function __construct()
7171
}
7272

7373
/**
74-
* Define o tempo máximo do pedido
74+
* Define o tempo máximo do pedido.
7575
*
76-
* @param int $timeout Em segundos
76+
* @param int $timeout Em segundos.
7777
*
7878
* @return \Crphp\Webservice\ClienteGenerico
7979
*/
@@ -194,7 +194,7 @@ public function getHeader()
194194
}
195195

196196
/**
197-
* Retorna o xml submetido
197+
* Retorna o xml submetido.
198198
*
199199
* @return string
200200
*/
@@ -206,7 +206,7 @@ public function getRequest()
206206
/**
207207
* Retorna o output devolvido pelo servidor alvo.
208208
*
209-
* @return null|string Em caso de sucesso retorna vazio, para erro retorna string
209+
* @return null|string Em caso de sucesso retorna vazio, para erro retorna string.
210210
*/
211211
public function getResponse()
212212
{

src/Soap.php

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/Traits/FormatarXML.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ trait FormatarXML {
1111
*
1212
* @param string $xml
1313
*
14-
* @return null|string Se não tiver dado para transformação retorna null
14+
* @return null|string Se não tiver dado para transformação retorna null.
1515
*/
1616
public function formatXML($xml)
1717
{

0 commit comments

Comments
 (0)