PageRenderTime 36ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/service/core/PHP5Soap.php

https://bitbucket.org/cviolette/sugarcrm
PHP | 168 lines | 102 code | 20 blank | 46 comment | 21 complexity | bec53408906a366dd024abff4ef6d5f2 MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. /*********************************************************************************
  2. * SugarCRM Community Edition is a customer relationship management program developed by
  3. * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it under
  6. * the terms of the GNU Affero General Public License version 3 as published by the
  7. * Free Software Foundation with the addition of the following permission added
  8. * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  9. * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
  10. * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  14. * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  15. * details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License along with
  18. * this program; if not, see http://www.gnu.org/licenses or write to the Free
  19. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  20. * 02110-1301 USA.
  21. *
  22. * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
  23. * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
  24. *
  25. * The interactive user interfaces in modified source and object code versions
  26. * of this program must display Appropriate Legal Notices, as required under
  27. * Section 5 of the GNU Affero General Public License version 3.
  28. *
  29. * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
  30. * these Appropriate Legal Notices must retain the display of the "Powered by
  31. * SugarCRM" logo. If the display of the logo is not reasonably feasible for
  32. * technical reasons, the Appropriate Legal Notices must display the words
  33. * "Powered by SugarCRM".
  34. ********************************************************************************/
  35. <?php
  36. require('service/core/SugarSoapService.php');
  37. require('include/nusoap/nusoap.php');
  38. abstract class PHP5Soap extends SugarSoapService{
  39. private $nusoap_server = null;
  40. public function __construct($url){
  41. $this->soapURL = $url;
  42. ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
  43. global $HTTP_RAW_POST_DATA;
  44. if(!isset($HTTP_RAW_POST_DATA)) {
  45. $HTTP_RAW_POST_DATA = file_get_contents('php://input');
  46. }
  47. parent::__construct();
  48. }
  49. public function setObservers() {
  50. } // fn
  51. /**
  52. * Serves the Soap Request
  53. * @return
  54. */
  55. public function serve(){
  56. ob_clean();
  57. global $HTTP_RAW_POST_DATA;
  58. $GLOBALS['log']->debug("I am here1 ". $HTTP_RAW_POST_DATA);
  59. $qs = '';
  60. if (isset($_SERVER['QUERY_STRING'])) {
  61. $qs = $_SERVER['QUERY_STRING'];
  62. } elseif (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
  63. $qs = $HTTP_SERVER_VARS['QUERY_STRING'];
  64. } else {
  65. $qs = '';
  66. }
  67. if (stristr($qs, 'wsdl') || $HTTP_RAW_POST_DATA == ''){
  68. $wsdlCacheFile = $this->getWSDLPath(false);
  69. if (stristr($qs, 'wsdl')) {
  70. $contents = @sugar_file_get_contents($wsdlCacheFile);
  71. if($contents !== false) {
  72. header("Content-Type: text/xml; charset=ISO-8859-1\r\n");
  73. print $contents;
  74. } // if
  75. } else {
  76. $this->nusoap_server->service($HTTP_RAW_POST_DATA);
  77. } // else
  78. } else {
  79. $this->server->handle();
  80. }
  81. ob_end_flush();
  82. flush();
  83. }
  84. private function generateSoapServer() {
  85. if ($this->server == null) {
  86. $soap_url = $this->getSoapURL() . "?wsdl";
  87. $this->server = new SoapServer($this->getWSDLPath(true), array('soap_version'=>SOAP_1_2, 'encoding'=>'ISO-8859-1'));
  88. }
  89. } // fn
  90. private function generateNuSoap() {
  91. if ($this->nusoap_server == null) {
  92. $this->nusoap_server = new soap_server();
  93. $this->nusoap_server->configureWSDL('sugarsoap', $this->getNameSpace(), "");
  94. $this->nusoap_server->register_class('SugarWebServiceImpl');
  95. } // if
  96. } // fn
  97. public function getWSDLPath($generateWSDL) {
  98. $wsdlURL = $this->getSoapURL().'?wsdl';
  99. $wsdlCacheFile = 'upload://wsdlcache-' . md5($wsdlURL);
  100. if ($generateWSDL) {
  101. $oldqs = $_SERVER['QUERY_STRING'];
  102. $_SERVER['QUERY_STRING'] = "wsdl";
  103. $this->nusoap_server->service($wsdlURL);
  104. $_SERVER['QUERY_STRING'] = $oldqs;
  105. file_put_contents($wsdlCacheFile, ob_get_contents());
  106. return $wsdlCacheFile;
  107. //ob_clean();
  108. } else {
  109. return $wsdlCacheFile;
  110. }
  111. } // fn
  112. public function getNameSpace() {
  113. return $this->soapURL;
  114. } // fn
  115. /**
  116. * This function allows specifying what version of PHP soap to use
  117. * PHP soap supports version 1.1 and 1.2.
  118. * @return
  119. * @param $version String[optional]
  120. */
  121. public function setSoapVersion($version='1.1'){
  122. //PHP SOAP supports 1.1 and 1.2 only currently
  123. $this->soap_version = ($version == '1.2')?'1.2':'1.1';
  124. }
  125. public function error($errorObject){
  126. $this->server->fault($errorObject->getFaultCode(), $errorObject->getName(), '', $errorObject->getDescription()); }
  127. public function registerImplClass($implementationClass){
  128. if (empty($implementationClass)) {
  129. $implementationClass = $this->implementationClass;
  130. } // if
  131. $this->generateSoapServer();
  132. $this->server->setClass($implementationClass);
  133. parent::setObservers();
  134. }
  135. function registerClass($registryClass){
  136. $this->registryClass = $registryClass;
  137. }
  138. public function registerType($name, $typeClass, $phpType, $compositor, $restrictionBase, $elements, $attrs=array(), $arrayType=''){
  139. $this->nusoap_server->wsdl->addComplexType($name, $typeClass, $phpType, $compositor, $restrictionBase, $elements, $attrs, $arrayType);
  140. }
  141. function registerFunction($function, $input, $output){
  142. if(in_array($function, $this->excludeFunctions))return;
  143. if ($this->nusoap_server == null) {
  144. $this->generateNuSoap();
  145. } // if
  146. $this->nusoap_server->register($function, $input, $output, $this->getNameSpace());
  147. }
  148. }