Tutorial Extension  1.0.0
SellerDeck Extensions - Tutorial Extension
CSDApiSoapClient.php
1 <?php
2 
3 /**
4  * CSDApiSoapClient.php - Implementation file for SellerDeck SOAP API class.
5  *
6  * @package SellerDeck Extensions
7  *
8  * @author Péter Erdődi
9  * @copyright © SellerDeck Ltd 2015. All rights reserved.
10  */
11 
12 namespace SDExtension;
13 
15  {
16 
17  /**
18  * @const int Maximum number of retry loops when a Soap Call fails
19  */
20  const MAX_WAIT = 100;
21 
22  /**
23  * @var SoapClient Soap Client Object
24  */
25  private $m_oSoapClient;
26 
27  /**
28  * @var bool Do we use retry loop or not when a Soap Call fails?
29  */
30  private $m_bSoapCallLoop;
31 
32  /**
33  * __construct - Object constructor method
34  *
35  * Initializes the member variables
36  *
37  * @access public
38  * @param SoapClient $oSoapClient Soap Client Object
39  * @param bool $bSoapCallLoop Do we use retry loop or not when a Soap Call fails?
40  * @return void
41  */
42  public function __construct($oSoapClient = null, $bSoapCallLoop = false)
43  {
44  $this->m_oSoapClient = $oSoapClient;
45  $this->m_bSoapCallLoop = $bSoapCallLoop;
46  }
47 
48  /**
49  * __call - Soap Function caller (PHP Magic Method)
50  *
51  * @access public
52  * @param string $sFuncName Soap Function name
53  * @param array $aArguments Soap Function arguments
54  * @return int Error code
55  * @return mixed Soap Function call result
56  */
57  public function __call($sFuncName, $aArguments)
58  {
59  //
60  // Do we use retry loop or not when a Soap Call fails?
61  //
62  if ($this->m_bSoapCallLoop)
63  {
64  //
65  // The Result variable is null by default
66  //
67  $nResult = null;
68  //
69  // Loop counter
70  //
71  $iCount = 0;
72  do
73  {
74  //
75  // Sleep time is increasing by each loop
76  // * 1000 means we ccount in milliseconds, not microseconds
77  //
78  usleep($iCount * 1000);
79  $iCount++;
80  //
81  // Calling Soap Function
82  //
83  $nResult = $this->m_oSoapClient->__call($sFuncName, $aArguments);
84  }
85  //
86  // Do that, while there's an error...
87  //
88  while ($nResult instanceof SoapFault && $iCount < self::MAX_WAIT);
89  //
90  // Returns the Function result or error, if there were errors MAX_WAIT times
91  //
92  return $nResult;
93  }
94  else
95  {
96  //
97  // Returns the Function result or error
98  //
99  return $this->m_oSoapClient->__call($sFuncName, $aArguments);
100  }
101  }
102 
103  }
__construct($oSoapClient=null, $bSoapCallLoop=false)
__call($sFuncName, $aArguments)