-
Notifications
You must be signed in to change notification settings - Fork 2
/
SoapClient.php
executable file
·87 lines (85 loc) · 2.72 KB
/
SoapClient.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
namespace SoapClient;
/**
* This class can be overridden at your will.
* Its only purpose is to show you how you can use your own SoapClient client.
*/
class SoapClient extends \SoapClient
{
/**
* @var string
*/
protected $lastModifiedRequest;
/**
* @param string $request
* @param string $location
* @param string $action
* @param string $version
* @param number $one_way
* @return mixed
*/
public function __doRequest($request, $location, $action, $version, $one_way = 0)
{
$this->removeEmptyTags($request);
return parent::__doRequest($this->__getLastRequest(), $location, $action, $version, $one_way);
}
/**
* Returns last request
* @see SoapClient::__getLastRequest()
* @return string
*/
public function __getLastRequest()
{
return $this->lastModifiedRequest;
}
/**
* Sets last request values
* @param string $_lastRequest
* @return string
*/
public function __setLastRequest($lastRequest)
{
return ($this->lastModifiedRequest = $lastRequest);
}
/**
* Removes empty tags from XML
* @param string $xml
* @param array $exceptTags
* @return string
*/
private function removeEmptyTags($xml, $exceptTags = array())
{
if (!empty($xml)) {
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->formatOutput = true;
if ($dom->loadXML($xml) && $dom->hasChildNodes()) {
$mainNode = $dom->childNodes->item(0);
self::removeEmptyTagsFromDomNode($mainNode, $exceptTags);
$xml = $dom->saveXML($mainNode);
}
}
return $this->__setLastRequest($xml);
}
/**
* Removes empty tags from \DOMNode
* @uses RemoveEmptyRequestTags::removeEmptyTagsFromDomNode()
* @param \DOMNode $domNode
* @return void
*/
private static function removeEmptyTagsFromDomNode(\DOMNode &$domNode, $exceptTags = array())
{
if ($domNode->hasChildNodes()) {
foreach ($domNode->childNodes as $childNode) {
self::removeEmptyTagsFromDomNode($childNode, $exceptTags);
}
} elseif (trim($domNode->nodeValue) === '' && !in_array($domNode->nodeName, $exceptTags) && $domNode->attributes->length === 0) {
/**
* As the parent might not have returned an empty value as it contained this child
* we go process back the parent to be sure that he validated as not empty
*/
$parentNode = $domNode->parentNode;
$domNode->parentNode->removeChild($domNode);
self::removeEmptyTagsFromDomNode($parentNode, $exceptTags);
}
}
}