/SCA/Bindings/ebaysoap/Proxy.php

https://github.com/CloCkWeRX/sdo · PHP · 167 lines · 87 code · 19 blank · 61 comment · 19 complexity · b6572e4b633ec895879543a80f932f50 MD5 · raw file

  1. <?php
  2. /**
  3. * +-----------------------------------------------------------------------------+
  4. * | (c) Copyright IBM Corporation 2007. |
  5. * | All Rights Reserved. |
  6. * +-----------------------------------------------------------------------------+
  7. * | Licensed under the Apache License, Version 2.0 (the "License"); you may not |
  8. * | use this file except in compliance with the License. You may obtain a copy |
  9. * | of the License at - |
  10. * | |
  11. * | http://www.apache.org/licenses/LICENSE-2.0 |
  12. * | |
  13. * | Unless required by applicable law or agreed to in writing, software |
  14. * | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
  15. * | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
  16. * | See the License for the specific language governing permissions and |
  17. * | limitations under the License. |
  18. * +-----------------------------------------------------------------------------+
  19. * | Author: Graham Charters, Caroline Maynard |
  20. * +-----------------------------------------------------------------------------+
  21. * $Id: Proxy.php 254122 2008-03-03 17:56:38Z mfp $
  22. *
  23. * PHP Version 5
  24. *
  25. * @category SCA
  26. * @package SCA_SDO
  27. * @author Simon Laws <slaws@php.net>
  28. * @license Apache http://www.apache.org/licenses/LICENSE-2.0
  29. * @link http://www.osoa.org/display/PHP/
  30. */
  31. require_once 'SCA/SCA_Exceptions.php';
  32. require_once 'SCA/SCA_Helper.php';
  33. require_once 'SCA/Bindings/soap/Proxy.php';
  34. require_once 'SCA/Bindings/ebaysoap/Mapper.php';
  35. if (!class_exists('SCA_Bindings_soap_Proxy', false)) {
  36. trigger_error("Cannot use SCA ebay soap binding as the SCA soap binding is not loaded", E_USER_WARNING);
  37. return;
  38. }
  39. /**
  40. * SCA_Bindings_ebaysoap_Proxy
  41. *
  42. * @category SCA
  43. * @package SCA_SDO
  44. * @author Simon Laws <slaws@php.net>
  45. * @license Apache http://www.apache.org/licenses/LICENSE-2.0
  46. * @link http://www.osoa.org/display/PHP/
  47. */
  48. class SCA_Bindings_Ebaysoap_Proxy extends SCA_Bindings_Soap_Proxy
  49. {
  50. protected $sdo_type_handler_class_name = "SCA_Bindings_ebaysoap_Mapper";
  51. /**
  52. * Determine if dependencies are available
  53. *
  54. * @return bool
  55. */
  56. public static function dependenciesLoaded()
  57. {
  58. $dependenciesLoaded = false;
  59. if (extension_loaded('openssl')) {
  60. $dependenciesLoaded = true;
  61. }
  62. return $dependenciesLoaded;
  63. }
  64. /**
  65. * Proxy constructor
  66. *
  67. * @param string $target Target URI
  68. * @param string $base_path_for_relative_paths Base path
  69. * @param string $binding_config Config
  70. */
  71. public function __construct($target, $base_path_for_relative_paths, $binding_config)
  72. {
  73. SCA::$logger->log('Entering');
  74. if (!SCA_Bindings_ebaysoap_Proxy::dependenciesLoaded()) {
  75. SCA::$logger->log('eBay soap binding requires the openssl extension, but it is not loaded.');
  76. throw new SCA_RuntimeException('eBay soap binding requires the openssl extension, but it is not loaded.');
  77. }
  78. $binding_config = SCA_Helper::mergeBindingIniAndConfig($binding_config, $base_path_for_relative_paths);
  79. // Check that all the required configuration has been provided
  80. if (!key_exists('siteid', $binding_config) || empty($binding_config['siteid'])) {
  81. SCA::$logger->log('eBay soap binding configuration missing: siteid.');
  82. throw new SCA_RuntimeException('eBay soap binding configuration missing: siteid.');
  83. }
  84. if (!key_exists('version', $binding_config) || empty($binding_config['version'])) {
  85. SCA::$logger->log('eBay soap binding configuration missing: version.');
  86. throw new SCA_RuntimeException('eBay soap binding configuration missing: version.');
  87. }
  88. if (!key_exists('authtoken', $binding_config) || empty($binding_config['authtoken'])) {
  89. SCA::$logger->log('eBay soap binding configuration missing: authtoken.');
  90. throw new SCA_RuntimeException('eBay soap binding configuration missing: authtoken.');
  91. }
  92. if (!key_exists('routing', $binding_config) || empty($binding_config['routing'])) {
  93. SCA::$logger->log('eBay soap binding configuration missing: routing.');
  94. throw new SCA_RuntimeException('eBay soap binding configuration missing: routing.');
  95. }
  96. if (!key_exists('appid', $binding_config) || empty($binding_config['appid'])) {
  97. SCA::$logger->log('eBay soap binding configuration missing: appid.');
  98. throw new SCA_RuntimeException('eBay soap binding configuration missing: appid.');
  99. }
  100. if (!key_exists('devid', $binding_config) || empty($binding_config['devid'])) {
  101. SCA::$logger->log('eBay soap binding configuration missing: devid.');
  102. throw new SCA_RuntimeException('eBay soap binding configuration missing: devid.');
  103. }
  104. if (!key_exists('authcert', $binding_config) || empty($binding_config['authcert'])) {
  105. SCA::$logger->log('eBay soap binding configuration missing: authcert.');
  106. throw new SCA_RuntimeException('eBay soap binding configuration missing: authcert.');
  107. }
  108. if (!key_exists('location', $binding_config) || empty($binding_config['location'])) {
  109. SCA::$logger->log('eBay soap binding configuration missing: location.');
  110. throw new SCA_RuntimeException('eBay soap binding configuration missing: location.');
  111. }
  112. parent::__construct($target, $base_path_for_relative_paths, $binding_config);
  113. SCA::$logger->log('Leaving');
  114. }
  115. /**
  116. * Call
  117. *
  118. * @param string $method_name Method name
  119. * @param array $arguments Arguments
  120. *
  121. * @return mixed
  122. */
  123. public function __call($method_name, $arguments)
  124. {
  125. SCA::$logger->log('Entering');
  126. // Build up the Url Query String Paramters
  127. $query_params = array('callname' => $method_name,
  128. 'siteid' => $this->config['siteid'],
  129. 'version' => $this->config['version'],
  130. 'appid' => $this->config['appid'],
  131. 'Routing' => $this->config['routing']);
  132. parent::__setQueryParams($query_params);
  133. // Build up the security header
  134. $requester_credentials = $this->createDataObject('urn:ebay:apis:eBLBaseComponents', 'CustomSecurityHeaderType');
  135. $requester_credentials->eBayAuthToken = $this->config['authtoken'];
  136. $credentials = $requester_credentials->createDataObject('Credentials');
  137. $credentials->AppId = $this->config['appid'];
  138. $credentials->DevId = $this->config['devid'];
  139. $credentials->AuthCert = $this->config['authcert'];
  140. parent::__setSoapHeader(
  141. $requester_credentials,
  142. 'urn:ebay:apis:eBLBaseComponents',
  143. 'RequesterCredentials'
  144. );
  145. $return = parent::__call($method_name, $arguments);
  146. return $return;
  147. }
  148. }