]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - service/core/NusoapSoap.php
Release 6.4.0
[Github/sugarcrm.git] / service / core / NusoapSoap.php
1 <?php
2  if(!defined('sugarEntry'))define('sugarEntry', true);
3 /*********************************************************************************
4  * SugarCRM Community Edition is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38 require('service/core/SugarSoapService.php');
39 require('include/nusoap/nusoap.php');
40
41 /**
42  * This is an abstract class for the soap implementation for using NUSOAP. This class is responsible for making
43  * all NUSOAP call by passing the client's request to NUSOAP server and seding response back to client
44  * @api
45  */
46 abstract class NusoapSoap extends SugarSoapService{
47         /**
48          * This is the constructor. It creates an instance of NUSOAP server.
49          *
50          * @param String $url - This is the soap URL
51          * @access public
52          */
53         public function __construct($url){
54                 $GLOBALS['log']->info('Begin: NusoapSoap->__construct');
55                 $this->server = new soap_server();
56                 $this->soapURL = $url;
57                 $this->server->configureWSDL('sugarsoap', $this->getNameSpace(), $url);
58                 if(!isset($GLOBALS['HTTP_RAW_POST_DATA']))$GLOBALS['HTTP_RAW_POST_DATA'] = file_get_contents('php://input');
59                 parent::__construct();
60                 $GLOBALS['log']->info('End: NusoapSoap->__construct');
61         } // ctor
62
63         /**
64          * Fallback function to catch unexpected failure in SOAP
65          */
66         public function shutdown()
67         {
68                 if($this->in_service) {
69                         $out = ob_get_contents();
70                         ob_end_clean();
71                         $GLOBALS['log']->info('NusoapSoap->shutdown: service died unexpectedly');
72                         $this->server->fault(-1, "Unknown error in SOAP call: service died unexpectedly", '', $out);
73                         $this->server->send_response();
74                 }
75         }
76
77         /**
78          * It passes request data to NUSOAP server and sends response back to client
79          * @access public
80          */
81         public function serve(){
82                 $GLOBALS['log']->info('Begin: NusoapSoap->serve');
83                 ob_clean();
84                 $this->in_service = true;
85                 register_shutdown_function(array($this, "shutdown"));
86                 ob_start();
87                 $this->server->service($GLOBALS['HTTP_RAW_POST_DATA']);
88                 $this->in_service = false;
89                 ob_end_flush();
90                 flush();
91                 $GLOBALS['log']->info('End: NusoapSoap->serve');
92         } // fn
93
94         /**
95          * This method registers all the complex type with NUSOAP server so that proper WSDL can be generated
96          *
97          * @param String $name - name of complex type
98          * @param String $typeClass - (complexType|simpleType|attribute)
99          * @param String $phpType - array or struct
100          * @param String $compositor - (all|sequence|choice)
101          * @param String $restrictionBase - SOAP-ENC:Array or empty
102          * @param Array $elements - array ( name => array(name=>'',type=>'') )
103          * @param Array $attrs - array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'xsd:string[]'))
104          * @param String $arrayType - arrayType: namespace:name (xsd:string)
105          * @access public
106          */
107         public function registerType($name, $typeClass, $phpType, $compositor, $restrictionBase, $elements, $attrs=array(), $arrayType=''){
108                 $this->server->wsdl->addComplexType($name, $typeClass, $phpType, $compositor, $restrictionBase, $elements, $attrs, $arrayType);
109         } // fn
110
111         /**
112          * This method registers all the functions you want to expose as services with NUSOAP
113          *
114          * @param String $function - name of the function
115          * @param Array $input - assoc array of input values: key = param name, value = param type
116          * @param Array $output - assoc array of output values: key = param name, value = param type
117          * @access public
118          */
119         function registerFunction($function, $input, $output){
120                 if(in_array($function, $this->excludeFunctions))return;
121                 $use = false;
122                 $style = false;
123                 if (isset($_REQUEST['use']) && ($_REQUEST['use'] == 'literal')) {
124                         $use = "literal";
125                 } // if
126                 if (isset($_REQUEST['style']) && ($_REQUEST['style'] == 'document')) {
127                         $style = "document";
128                 } // if
129                 $this->server->register($function, $input, $output, $this->getNameSpace(), '',$style, $use);
130         } // fn
131
132         /**
133          * This function registers implementation class name with NUSOAP so when NUSOAP makes a call to a funciton,
134          * it will be made on this class object
135          *
136          * @param String $implementationClass
137          * @access public
138          */
139         function registerImplClass($implementationClass){
140                 $GLOBALS['log']->info('Begin: NusoapSoap->registerImplClass');
141                 if (empty($implementationClass)) {
142                         $implementationClass = $this->implementationClass;
143                 } // if
144                 $this->server->register_class($implementationClass);
145                 $GLOBALS['log']->info('End: NusoapSoap->registerImplClass');
146         } // fn
147
148         /**
149          * Sets the name of the registry class
150          *
151          * @param String $registryClass
152          * @access public
153          */
154         function registerClass($registryClass){
155                 $GLOBALS['log']->info('Begin: NusoapSoap->registerClass');
156                 $this->registryClass = $registryClass;
157                 $GLOBALS['log']->info('End: NusoapSoap->registerClass');
158         } // fn
159
160         /**
161          * This function sets the fault object on the NUSOAP
162          *
163          * @param SoapError $errorObject - This is an object of type SoapError
164          * @access public
165          */
166         public function error($errorObject){
167                 $GLOBALS['log']->info('Begin: NusoapSoap->error');
168                 $this->server->fault($errorObject->getFaultCode(), $errorObject->getName(), '', $errorObject->getDescription());
169                 $GLOBALS['log']->info('Begin: NusoapSoap->error');
170         } // fn
171
172 } // clazz