Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Client.php
Go to the documentation of this file.
1 <?php
26 #require_once 'Zend/Soap/Server.php';
27 
31 #require_once 'Zend/Soap/Client/Local.php';
32 
36 #require_once 'Zend/Soap/Client/Common.php';
37 
48 {
53  protected $_encoding = 'UTF-8';
54 
59  protected $_classmap = null;
60 
65  protected $_faultExceptions = array();
66 
71  protected $_soapVersion = SOAP_1_2;
72 
74  protected $_uri = null;
75  protected $_location = null;
76  protected $_style = null;
77  protected $_use = null;
78  protected $_login = null;
79  protected $_password = null;
80  protected $_proxy_host = null;
81  protected $_proxy_port = null;
82  protected $_proxy_login = null;
83  protected $_proxy_password = null;
84  protected $_local_cert = null;
85  protected $_passphrase = null;
86  protected $_compression = null;
87  protected $_connection_timeout = null;
88  protected $_stream_context = null;
89  protected $_features = null;
90  protected $_cache_wsdl = null;
91  protected $_user_agent = null;
92  protected $_exceptions = null;
93 
100  protected $_wsdl = null;
101 
107  protected $_soapClient;
108 
114  protected $_lastMethod = '';
115 
123  protected $_soapInputHeaders = array();
124 
132  protected $_permanentSoapInputHeaders = array();
133 
141  protected $_soapOutputHeaders = array();
142 
149  public function __construct($wsdl = null, $options = null)
150  {
151  if (!extension_loaded('soap')) {
152  #require_once 'Zend/Soap/Client/Exception.php';
153  throw new Zend_Soap_Client_Exception('SOAP extension is not loaded.');
154  }
155 
156  if ($wsdl !== null) {
157  $this->setWsdl($wsdl);
158  }
159  if ($options !== null) {
160  $this->setOptions($options);
161  }
162  }
163 
170  public function setWsdl($wsdl)
171  {
172  $this->_wsdl = $wsdl;
173  $this->_soapClient = null;
174 
175  return $this;
176  }
177 
183  public function getWsdl()
184  {
185  return $this->_wsdl;
186  }
187 
197  public function setOptions($options)
198  {
199  if($options instanceof Zend_Config) {
200  $options = $options->toArray();
201  }
202 
203  foreach ($options as $key => $value) {
204  switch ($key) {
205  case 'classmap':
206  case 'classMap':
207  $this->setClassmap($value);
208  break;
209  case 'encoding':
210  $this->setEncoding($value);
211  break;
212  case 'soapVersion':
213  case 'soap_version':
214  $this->setSoapVersion($value);
215  break;
216  case 'wsdl':
217  $this->setWsdl($value);
218  break;
219  case 'uri':
220  $this->setUri($value);
221  break;
222  case 'location':
223  $this->setLocation($value);
224  break;
225  case 'style':
226  $this->setStyle($value);
227  break;
228  case 'use':
229  $this->setEncodingMethod($value);
230  break;
231  case 'login':
232  $this->setHttpLogin($value);
233  break;
234  case 'password':
235  $this->setHttpPassword($value);
236  break;
237  case 'proxy_host':
238  $this->setProxyHost($value);
239  break;
240  case 'proxy_port':
241  $this->setProxyPort($value);
242  break;
243  case 'proxy_login':
244  $this->setProxyLogin($value);
245  break;
246  case 'proxy_password':
247  $this->setProxyPassword($value);
248  break;
249  case 'local_cert':
250  $this->setHttpsCertificate($value);
251  break;
252  case 'passphrase':
254  break;
255  case 'compression':
257  break;
258  case 'stream_context':
259  $this->setStreamContext($value);
260  break;
261  case 'features':
262  $this->setSoapFeatures($value);
263  break;
264  case 'cache_wsdl':
265  $this->setWsdlCache($value);
266  break;
267  case 'useragent':
268  case 'userAgent':
269  case 'user_agent':
270  $this->setUserAgent($value);
271  break;
272  case 'exceptions':
273  $this->setExceptions($value);
274  break;
275 
276  // Not used now
277  // case 'connection_timeout':
278  // $this->_connection_timeout = $value;
279  // break;
280 
281  default:
282  #require_once 'Zend/Soap/Client/Exception.php';
283  throw new Zend_Soap_Client_Exception('Unknown SOAP client option');
284  break;
285  }
286  }
287 
288  return $this;
289  }
290 
296  public function getOptions()
297  {
298  $options = array();
299 
300  $options['classmap'] = $this->getClassmap();
301  $options['encoding'] = $this->getEncoding();
302  $options['soap_version'] = $this->getSoapVersion();
303  $options['wsdl'] = $this->getWsdl();
304  $options['uri'] = $this->getUri();
305  $options['location'] = $this->getLocation();
306  $options['style'] = $this->getStyle();
307  $options['use'] = $this->getEncodingMethod();
308  $options['login'] = $this->getHttpLogin();
309  $options['password'] = $this->getHttpPassword();
310  $options['proxy_host'] = $this->getProxyHost();
311  $options['proxy_port'] = $this->getProxyPort();
312  $options['proxy_login'] = $this->getProxyLogin();
313  $options['proxy_password'] = $this->getProxyPassword();
314  $options['local_cert'] = $this->getHttpsCertificate();
315  $options['passphrase'] = $this->getHttpsCertPassphrase();
316  $options['compression'] = $this->getCompressionOptions();
317  //$options['connection_timeout'] = $this->_connection_timeout;
318  $options['stream_context'] = $this->getStreamContext();
319  $options['cache_wsdl'] = $this->getWsdlCache();
320  $options['features'] = $this->getSoapFeatures();
321  $options['user_agent'] = $this->getUserAgent();
322  $options['exceptions'] = $this->getExceptions();
323 
324  foreach ($options as $key => $value) {
325  /*
326  * ugly hack as I don't know if checking for '=== null'
327  * breaks some other option
328  */
329  if (in_array($key, array('user_agent', 'cache_wsdl', 'compression', 'exceptions'))) {
330  if ($value === null) {
331  unset($options[$key]);
332  }
333  } else {
334  if ($value == null) {
335  unset($options[$key]);
336  }
337  }
338  }
339 
340  return $options;
341  }
342 
350  public function setSoapVersion($version)
351  {
352  if (!in_array($version, array(SOAP_1_1, SOAP_1_2))) {
353  #require_once 'Zend/Soap/Client/Exception.php';
354  throw new Zend_Soap_Client_Exception('Invalid soap version specified. Use SOAP_1_1 or SOAP_1_2 constants.');
355  }
356  $this->_soapVersion = $version;
357 
358  $this->_soapClient = null;
359 
360  return $this;
361  }
362 
368  public function getSoapVersion()
369  {
370  return $this->_soapVersion;
371  }
372 
380  public function setClassmap(array $classmap)
381  {
382  foreach ($classmap as $type => $class) {
383  if (!class_exists($class)) {
384  #require_once 'Zend/Soap/Client/Exception.php';
385  throw new Zend_Soap_Client_Exception('Invalid class in class map');
386  }
387  }
388 
389  $this->_classmap = $classmap;
390 
391  $this->_soapClient = null;
392 
393  return $this;
394  }
395 
401  public function getClassmap()
402  {
403  return $this->_classmap;
404  }
405 
413  public function setEncoding($encoding)
414  {
415  if (!is_string($encoding)) {
416  #require_once 'Zend/Soap/Client/Exception.php';
417  throw new Zend_Soap_Client_Exception('Invalid encoding specified');
418  }
419 
420  $this->_encoding = $encoding;
421 
422  $this->_soapClient = null;
423 
424  return $this;
425  }
426 
432  public function getEncoding()
433  {
434  return $this->_encoding;
435  }
436 
444  public function validateUrn($urn)
445  {
446  $scheme = parse_url($urn, PHP_URL_SCHEME);
447  if ($scheme === false || $scheme === null) {
448  #require_once 'Zend/Soap/Client/Exception.php';
449  throw new Zend_Soap_Client_Exception('Invalid URN');
450  }
451 
452  return true;
453 
454  }
455 
465  public function setUri($uri)
466  {
467  $this->validateUrn($uri);
468  $this->_uri = $uri;
469 
470  $this->_soapClient = null;
471 
472  return $this;
473  }
474 
480  public function getUri()
481  {
482  return $this->_uri;
483  }
484 
494  public function setLocation($location)
495  {
496  $this->validateUrn($location);
497  $this->_location = $location;
498 
499  $this->_soapClient = null;
500 
501  return $this;
502  }
503 
509  public function getLocation()
510  {
511  return $this->_location;
512  }
513 
521  public function setStyle($style)
522  {
523  if (!in_array($style, array(SOAP_RPC, SOAP_DOCUMENT))) {
524  #require_once 'Zend/Soap/Client/Exception.php';
525  throw new Zend_Soap_Client_Exception('Invalid request style specified. Use SOAP_RPC or SOAP_DOCUMENT constants.');
526  }
527 
528  $this->_style = $style;
529 
530  $this->_soapClient = null;
531 
532  return $this;
533  }
534 
540  public function getStyle()
541  {
542  return $this->_style;
543  }
544 
552  public function setEncodingMethod($use)
553  {
554  if (!in_array($use, array(SOAP_ENCODED, SOAP_LITERAL))) {
555  #require_once 'Zend/Soap/Client/Exception.php';
556  throw new Zend_Soap_Client_Exception('Invalid message encoding method. Use SOAP_ENCODED or SOAP_LITERAL constants.');
557  }
558 
559  $this->_use = $use;
560 
561  $this->_soapClient = null;
562 
563  return $this;
564  }
565 
571  public function getEncodingMethod()
572  {
573  return $this->_use;
574  }
575 
582  public function setHttpLogin($login)
583  {
584  $this->_login = $login;
585 
586  $this->_soapClient = null;
587 
588  return $this;
589  }
590 
596  public function getHttpLogin()
597  {
598  return $this->_login;
599  }
600 
607  public function setHttpPassword($password)
608  {
609  $this->_password = $password;
610 
611  $this->_soapClient = null;
612 
613  return $this;
614  }
615 
621  public function getHttpPassword()
622  {
623  return $this->_password;
624  }
625 
632  public function setProxyHost($proxyHost)
633  {
634  $this->_proxy_host = $proxyHost;
635 
636  $this->_soapClient = null;
637 
638  return $this;
639  }
640 
646  public function getProxyHost()
647  {
648  return $this->_proxy_host;
649  }
650 
657  public function setProxyPort($proxyPort)
658  {
659  $this->_proxy_port = (int)$proxyPort;
660 
661  $this->_soapClient = null;
662 
663  return $this;
664  }
665 
671  public function getProxyPort()
672  {
673  return $this->_proxy_port;
674  }
675 
682  public function setProxyLogin($proxyLogin)
683  {
684  $this->_proxy_login = $proxyLogin;
685 
686  $this->_soapClient = null;
687 
688  return $this;
689  }
690 
696  public function getProxyLogin()
697  {
698  return $this->_proxy_login;
699  }
700 
707  public function setProxyPassword($proxyPassword)
708  {
709  $this->_proxy_password = $proxyPassword;
710 
711  $this->_soapClient = null;
712 
713  return $this;
714  }
715 
723  public function setHttpsCertificate($localCert)
724  {
725  if (!is_readable($localCert)) {
726  #require_once 'Zend/Soap/Client/Exception.php';
727  throw new Zend_Soap_Client_Exception('Invalid HTTPS client certificate path.');
728  }
729 
730  $this->_local_cert = $localCert;
731 
732  $this->_soapClient = null;
733 
734  return $this;
735  }
736 
742  public function getHttpsCertificate()
743  {
744  return $this->_local_cert;
745  }
746 
753  public function setHttpsCertPassphrase($passphrase)
754  {
755  $this->_passphrase = $passphrase;
756 
757  $this->_soapClient = null;
758 
759  return $this;
760  }
761 
767  public function getHttpsCertPassphrase()
768  {
769  return $this->_passphrase;
770  }
771 
778  public function setCompressionOptions($compressionOptions)
779  {
780  if ($compressionOptions === null) {
781  $this->_compression = null;
782  } else {
783  $this->_compression = (int)$compressionOptions;
784  }
785  $this->_soapClient = null;
786  return $this;
787  }
788 
794  public function getCompressionOptions()
795  {
796  return $this->_compression;
797  }
798 
804  public function getProxyPassword()
805  {
806  return $this->_proxy_password;
807  }
808 
814  public function setStreamContext($context)
815  {
816  if(!is_resource($context) || get_resource_type($context) !== "stream-context") {
820  #require_once "Zend/Soap/Client/Exception.php";
821  throw new Zend_Soap_Client_Exception(
822  "Invalid stream context resource given."
823  );
824  }
825 
826  $this->_stream_context = $context;
827  return $this;
828  }
829 
835  public function getStreamContext()
836  {
837  return $this->_stream_context;
838  }
839 
846  public function setSoapFeatures($feature)
847  {
848  $this->_features = $feature;
849 
850  $this->_soapClient = null;
851  return $this;
852  }
853 
859  public function getSoapFeatures()
860  {
861  return $this->_features;
862  }
863 
870  public function setWsdlCache($caching)
871  {
872  if ($caching === null) {
873  $this->_cache_wsdl = null;
874  } else {
875  $this->_cache_wsdl = (int)$caching;
876  }
877  return $this;
878  }
879 
885  public function getWsdlCache()
886  {
887  return $this->_cache_wsdl;
888  }
889 
896  public function setUserAgent($userAgent)
897  {
898  if ($userAgent === null) {
899  $this->_user_agent = null;
900  } else {
901  $this->_user_agent = (string)$userAgent;
902  }
903  return $this;
904  }
905 
911  public function getUserAgent()
912  {
913  return $this->_user_agent;
914  }
915 
927  public function setExceptions($exceptions)
928  {
929  $this->_exceptions = (bool) $exceptions;
930 
931  return $this;
932  }
933 
944  public function getExceptions()
945  {
946  return $this->_exceptions;
947  }
948 
954  public function getLastRequest()
955  {
956  if ($this->_soapClient !== null) {
957  return $this->_soapClient->__getLastRequest();
958  }
959 
960  return '';
961  }
962 
968  public function getLastResponse()
969  {
970  if ($this->_soapClient !== null) {
971  return $this->_soapClient->__getLastResponse();
972  }
973 
974  return '';
975  }
976 
982  public function getLastRequestHeaders()
983  {
984  if ($this->_soapClient !== null) {
985  return $this->_soapClient->__getLastRequestHeaders();
986  }
987 
988  return '';
989  }
990 
996  public function getLastResponseHeaders()
997  {
998  if ($this->_soapClient !== null) {
999  return $this->_soapClient->__getLastResponseHeaders();
1000  }
1001 
1002  return '';
1003  }
1004 
1010  public function getLastMethod()
1011  {
1012  return $this->_lastMethod;
1013  }
1014 
1029  public function _doRequest(Zend_Soap_Client_Common $client, $request, $location, $action, $version, $one_way = null)
1030  {
1031  // Perform request as is
1032  if ($one_way == null) {
1033  return call_user_func(array($client,'SoapClient::__doRequest'), $request, $location, $action, $version);
1034  } else {
1035  return call_user_func(array($client,'SoapClient::__doRequest'), $request, $location, $action, $version, $one_way);
1036  }
1037  }
1038 
1044  protected function _initSoapClientObject()
1045  {
1046  $wsdl = $this->getWsdl();
1047  $options = array_merge($this->getOptions(), array('trace' => true));
1048 
1049  if ($wsdl == null) {
1050  if (!isset($options['location'])) {
1051  #require_once 'Zend/Soap/Client/Exception.php';
1052  throw new Zend_Soap_Client_Exception('\'location\' parameter is required in non-WSDL mode.');
1053  }
1054  if (!isset($options['uri'])) {
1055  #require_once 'Zend/Soap/Client/Exception.php';
1056  throw new Zend_Soap_Client_Exception('\'uri\' parameter is required in non-WSDL mode.');
1057  }
1058  } else {
1059  if (isset($options['use'])) {
1060  #require_once 'Zend/Soap/Client/Exception.php';
1061  throw new Zend_Soap_Client_Exception('\'use\' parameter only works in non-WSDL mode.');
1062  }
1063  if (isset($options['style'])) {
1064  #require_once 'Zend/Soap/Client/Exception.php';
1065  throw new Zend_Soap_Client_Exception('\'style\' parameter only works in non-WSDL mode.');
1066  }
1067  }
1068  unset($options['wsdl']);
1069 
1070  $this->_soapClient = new Zend_Soap_Client_Common(array($this, '_doRequest'), $wsdl, $options);
1071  }
1072 
1073 
1081  protected function _preProcessArguments($arguments)
1082  {
1083  // Do nothing
1084  return $arguments;
1085  }
1086 
1094  protected function _preProcessResult($result)
1095  {
1096  // Do nothing
1097  return $result;
1098  }
1099 
1107  public function addSoapInputHeader(SoapHeader $header, $permanent = false)
1108  {
1109  if ($permanent) {
1110  $this->_permanentSoapInputHeaders[] = $header;
1111  } else {
1112  $this->_soapInputHeaders[] = $header;
1113  }
1114 
1115  return $this;
1116  }
1117 
1123  public function resetSoapInputHeaders()
1124  {
1125  $this->_permanentSoapInputHeaders = array();
1126  $this->_soapInputHeaders = array();
1127 
1128  return $this;
1129  }
1130 
1137  {
1139  }
1140 
1148  public function __call($name, $arguments)
1149  {
1150  $soapClient = $this->getSoapClient();
1151 
1152  $this->_lastMethod = $name;
1153 
1154  $soapHeaders = array_merge($this->_permanentSoapInputHeaders, $this->_soapInputHeaders);
1155  $result = $soapClient->__soapCall($name,
1157  null, /* Options are already set to the SOAP client object */
1158  (count($soapHeaders) > 0)? $soapHeaders : null,
1159  $this->_soapOutputHeaders);
1160 
1161  // Reset non-permanent input headers
1162  $this->_soapInputHeaders = array();
1163 
1164  return $this->_preProcessResult($result);
1165  }
1166 
1167 
1174  public function getFunctions()
1175  {
1176  if ($this->getWsdl() == null) {
1177  #require_once 'Zend/Soap/Client/Exception.php';
1178  throw new Zend_Soap_Client_Exception('\'getFunctions\' method is available only in WSDL mode.');
1179  }
1180 
1181  $soapClient = $this->getSoapClient();
1182  return $soapClient->__getFunctions();
1183  }
1184 
1185 
1198  public function getTypes()
1199  {
1200  if ($this->getWsdl() == null) {
1201  #require_once 'Zend/Soap/Client/Exception.php';
1202  throw new Zend_Soap_Client_Exception('\'getTypes\' method is available only in WSDL mode.');
1203  }
1204 
1205  $soapClient = $this->getSoapClient();
1206 
1207  return $soapClient->__getTypes();
1208  }
1209 
1214  public function setSoapClient(SoapClient $soapClient)
1215  {
1216  $this->_soapClient = $soapClient;
1217  return $this;
1218  }
1219 
1223  public function getSoapClient()
1224  {
1225  if ($this->_soapClient == null) {
1226  $this->_initSoapClientObject();
1227  }
1228  return $this->_soapClient;
1229  }
1230 
1236  public function setCookie($cookieName, $cookieValue=null)
1237  {
1238  $soapClient = $this->getSoapClient();
1239  $soapClient->__setCookie($cookieName, $cookieValue);
1240  return $this;
1241  }
1242 }
setLocation($location)
Definition: Client.php:494
setCookie($cookieName, $cookieValue=null)
Definition: Client.php:1236
setProxyLogin($proxyLogin)
Definition: Client.php:682
setHttpsCertificate($localCert)
Definition: Client.php:723
setWsdl($wsdl)
Definition: Client.php:170
setStyle($style)
Definition: Client.php:521
setStreamContext($context)
Definition: Client.php:814
__call($name, $arguments)
Definition: Client.php:1148
getHttpsCertPassphrase()
Definition: Client.php:767
setHttpLogin($login)
Definition: Client.php:582
setClassmap(array $classmap)
Definition: Client.php:380
setEncodingMethod($use)
Definition: Client.php:552
getLastResponseHeaders()
Definition: Client.php:996
setHttpsCertPassphrase($passphrase)
Definition: Client.php:753
setSoapVersion($version)
Definition: Client.php:350
setWsdlCache($caching)
Definition: Client.php:870
getLastRequestHeaders()
Definition: Client.php:982
setProxyPassword($proxyPassword)
Definition: Client.php:707
$type
Definition: item.phtml:13
$_option $_optionId $class
Definition: date.phtml:13
$value
Definition: gender.phtml:16
setEncoding($encoding)
Definition: Client.php:413
setExceptions($exceptions)
Definition: Client.php:927
_doRequest(Zend_Soap_Client_Common $client, $request, $location, $action, $version, $one_way=null)
Definition: Client.php:1029
setOptions($options)
Definition: Client.php:197
$arguments
setCompressionOptions($compressionOptions)
Definition: Client.php:778
setSoapClient(SoapClient $soapClient)
Definition: Client.php:1214
setSoapFeatures($feature)
Definition: Client.php:846
setProxyPort($proxyPort)
Definition: Client.php:657
setHttpPassword($password)
Definition: Client.php:607
__construct($wsdl=null, $options=null)
Definition: Client.php:149
setUserAgent($userAgent)
Definition: Client.php:896
setProxyHost($proxyHost)
Definition: Client.php:632
_preProcessResult($result)
Definition: Client.php:1094
addSoapInputHeader(SoapHeader $header, $permanent=false)
Definition: Client.php:1107
$_permanentSoapInputHeaders
Definition: Client.php:132
getLastSoapOutputHeaderObjects()
Definition: Client.php:1136
_preProcessArguments($arguments)
Definition: Client.php:1081
validateUrn($urn)
Definition: Client.php:444
getCompressionOptions()
Definition: Client.php:794
if(!isset($_GET['name'])) $name
Definition: log.php:14