22 const OASIS =
"http://docs.oasis-open.org/wss/2004/01";
27 private static $logger =
null;
36 public function __construct($wsdl, $user, $password, $options) {
37 parent::__construct($wsdl, $options);
38 if (self::$logger ==
null) {
42 $this->password = $password;
50 public function call($method, $params=[]) {
51 $header = $this->generateWSSecurityHeader($this->user, $this->password);
52 $response = $this->__soapCall($method,
sizeof($params) > 0 ? [$params] : [],
null, $header);
54 return property_exists($response,
'return') ? $response->return : $response;
61 public function __doRequest($request, $location, $action, $version, $oneway=0){
62 if (self::$logger->isDebugEnabled()) {
63 self::$logger->debug(
"Request:");
64 self::$logger->debug($request);
66 $response = trim(parent::__doRequest($request, $location, $action, $version, $oneway));
67 if (self::$logger->isDebugEnabled()) {
68 self::$logger->debug(
"Response:");
69 self::$logger->debug($response);
72 $parsedResponse = preg_replace(
'/^(\x00\x00\xFE\xFF|\xFF\xFE\x00\x00|\xFE\xFF|\xFF\xFE|\xEF\xBB\xBF)/',
"", $response);
74 if (preg_match(
'/^<\?xml/', $parsedResponse) && !preg_match(
'/e>$/', $parsedResponse)) {
75 $parsedResponse .=
'e>';
77 return $parsedResponse;
87 private function generateWSSecurityHeader($user, $password) {
88 $xml =
'<wsse:Security SOAP-ENV:mustUnderstand="1" xmlns:wsse="'.self::OASIS.
'/oasis-200401-wss-wssecurity-secext-1.0.xsd">
90 <wsse:Username>'.$user.
'</wsse:Username>
91 <wsse:Password Type="'.self::OASIS.
'/oasis-200401-wss-username-token-profile-1.0#PasswordText">'.$password.
'</wsse:Password>
94 return new \SoapHeader(self::OASIS.
'/oasis-200401-wss-wssecurity-secext-1.0.xsd',
'Security',
new \SoapVar($xml, XSD_ANYXML),
true);
103 $requestHeaders = $this->__getLastRequestHeaders();
104 $request = $this->__getLastRequest();
105 $responseHeaders = $this->__getLastResponseHeaders();
106 $response = $this->__getLastResponse();
109 $msg .=
"Request Headers:\n" . $requestHeaders .
"\n";
110 $msg .=
"Request:\n" . $request .
"\n";
112 $msg .=
"Response Headers:\n" . $responseHeaders .
"\n";
113 $msg .=
"Response:\n" . $response .
"\n";