1 /*********************************************************************************
2 * SugarCRM Community Edition is a customer relationship management program developed by
3 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
37 require('service/core/SugarSoapService.php');
38 require('include/nusoap/nusoap.php');
40 abstract class PHP5Soap extends SugarSoapService{
41 private $nusoap_server = null;
42 public function __construct($url){
43 $this->soapURL = $url;
44 ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
45 global $HTTP_RAW_POST_DATA;
46 if(!isset($HTTP_RAW_POST_DATA)) {
47 $HTTP_RAW_POST_DATA = file_get_contents('php://input');
49 parent::__construct();
52 public function setObservers() {
57 * Serves the Soap Request
60 public function serve(){
62 global $HTTP_RAW_POST_DATA;
63 $GLOBALS['log']->debug("I am here1 ". $HTTP_RAW_POST_DATA);
65 if (isset($_SERVER['QUERY_STRING'])) {
66 $qs = $_SERVER['QUERY_STRING'];
67 } elseif (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
68 $qs = $HTTP_SERVER_VARS['QUERY_STRING'];
73 if (stristr($qs, 'wsdl') || $HTTP_RAW_POST_DATA == ''){
74 $wsdlCacheFile = $this->getWSDLPath(false);
75 if (stristr($qs, 'wsdl')) {
76 $contents = @sugar_file_get_contents($wsdlCacheFile);
77 if($contents !== false) {
78 header("Content-Type: text/xml; charset=ISO-8859-1\r\n");
82 $this->nusoap_server->service($HTTP_RAW_POST_DATA);
85 $this->server->handle();
91 private function generateSoapServer() {
92 if ($this->server == null) {
93 $soap_url = $this->getSoapURL() . "?wsdl";
94 $this->server = new SoapServer($this->getWSDLPath(true), array('soap_version'=>SOAP_1_2, 'encoding'=>'ISO-8859-1'));
98 private function generateNuSoap() {
99 if ($this->nusoap_server == null) {
100 $this->nusoap_server = new soap_server();
101 $this->nusoap_server->configureWSDL('sugarsoap', $this->getNameSpace(), "");
102 $this->nusoap_server->register_class('SugarWebServiceImpl');
106 public function getWSDLPath($generateWSDL) {
107 $wsdlURL = $this->getSoapURL().'?wsdl';
108 $wsdlCacheFile = 'upload://wsdlcache-' . md5($wsdlURL);
111 $oldqs = $_SERVER['QUERY_STRING'];
112 $_SERVER['QUERY_STRING'] = "wsdl";
113 $this->nusoap_server->service($wsdlURL);
114 $_SERVER['QUERY_STRING'] = $oldqs;
115 file_put_contents($wsdlCacheFile, ob_get_contents());
116 return $wsdlCacheFile;
119 return $wsdlCacheFile;
124 public function getNameSpace() {
125 return $this->soapURL;
129 * This function allows specifying what version of PHP soap to use
130 * PHP soap supports version 1.1 and 1.2.
132 * @param $version String[optional]
134 public function setSoapVersion($version='1.1'){
135 //PHP SOAP supports 1.1 and 1.2 only currently
136 $this->soap_version = ($version == '1.2')?'1.2':'1.1';
139 public function error($errorObject){
140 $this->server->fault($errorObject->getFaultCode(), $errorObject->getName(), '', $errorObject->getDescription()); }
142 public function registerImplClass($implementationClass){
143 if (empty($implementationClass)) {
144 $implementationClass = $this->implementationClass;
146 $this->generateSoapServer();
147 $this->server->setClass($implementationClass);
148 parent::setObservers();
151 function registerClass($registryClass){
152 $this->registryClass = $registryClass;
155 public function registerType($name, $typeClass, $phpType, $compositor, $restrictionBase, $elements, $attrs=array(), $arrayType=''){
156 $this->nusoap_server->wsdl->addComplexType($name, $typeClass, $phpType, $compositor, $restrictionBase, $elements, $attrs, $arrayType);
159 function registerFunction($function, $input, $output){
160 if(in_array($function, $this->excludeFunctions))return;
161 if ($this->nusoap_server == null) {
162 $this->generateNuSoap();
164 $this->nusoap_server->register($function, $input, $output, $this->getNameSpace());