]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - service/core/NusoapSoap.php
Release 6.1.4
[Github/sugarcrm.git] / service / core / NusoapSoap.php
1 <?php
2  if(!defined('sugarEntry'))define('sugarEntry', true);
3 /*********************************************************************************
4  * SugarCRM 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  *
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          * It passes request data to NUSOAP server and sends response back to client
65          * @access public
66          */
67         public function serve(){
68                 $GLOBALS['log']->info('Begin: NusoapSoap->serve');
69                 ob_clean();
70                 $this->server->service($GLOBALS['HTTP_RAW_POST_DATA']);
71                 ob_end_flush();
72                 flush();
73                 $GLOBALS['log']->info('End: NusoapSoap->serve');
74         } // fn
75
76         /**
77          * This method registers all the complex type with NUSOAP server so that proper WSDL can be generated
78          *
79          * @param String $name - name of complex type
80          * @param String $typeClass - (complexType|simpleType|attribute)
81          * @param String $phpType - array or struct
82          * @param String $compositor - (all|sequence|choice)
83          * @param String $restrictionBase - SOAP-ENC:Array or empty
84          * @param Array $elements - array ( name => array(name=>'',type=>'') )
85          * @param Array $attrs - array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'xsd:string[]'))
86          * @param String $arrayType - arrayType: namespace:name (xsd:string)
87          * @access public
88          */
89         public function registerType($name, $typeClass, $phpType, $compositor, $restrictionBase, $elements, $attrs=array(), $arrayType=''){
90                 $this->server->wsdl->addComplexType($name, $typeClass, $phpType, $compositor, $restrictionBase, $elements, $attrs, $arrayType);
91         } // fn
92         
93         /**
94          * This method registers all the functions you want to expose as services with NUSOAP
95          *
96          * @param String $function - name of the function
97          * @param Array $input - assoc array of input values: key = param name, value = param type
98          * @param Array $output - assoc array of output values: key = param name, value = param type
99          * @access public
100          */
101         function registerFunction($function, $input, $output){
102                 if(in_array($function, $this->excludeFunctions))return;         
103                 $use = false;
104                 $style = false;
105                 if (isset($_REQUEST['use']) && ($_REQUEST['use'] == 'literal')) {
106                         $use = "literal";
107                 } // if
108                 if (isset($_REQUEST['style']) && ($_REQUEST['style'] == 'document')) {
109                         $style = "document";
110                 } // if
111                 $this->server->register($function, $input, $output, $this->getNameSpace(), '',$style, $use);
112         } // fn
113         
114         /**
115          * This function registers implementation class name with NUSOAP so when NUSOAP makes a call to a funciton,
116          * it will be made on this class object
117          *
118          * @param String $implementationClass
119          * @access public
120          */
121         function registerImplClass($implementationClass){
122                 $GLOBALS['log']->info('Begin: NusoapSoap->registerImplClass');
123                 if (empty($implementationClass)) {
124                         $implementationClass = $this->implementationClass;
125                 } // if
126                 $this->server->register_class($implementationClass);
127                 $GLOBALS['log']->info('End: NusoapSoap->registerImplClass');
128         } // fn
129         
130         /**
131          * Sets the name of the registry class
132          *
133          * @param String $registryClass
134          * @access public
135          */
136         function registerClass($registryClass){
137                 $GLOBALS['log']->info('Begin: NusoapSoap->registerClass');
138                 $this->registryClass = $registryClass;
139                 $GLOBALS['log']->info('End: NusoapSoap->registerClass');
140         } // fn
141         
142         /**
143          * This function sets the fault object on the NUSOAP
144          *
145          * @param SoapError $errorObject - This is an object of type SoapError
146          * @access public
147          */
148         public function error($errorObject){
149                 $GLOBALS['log']->info('Begin: NusoapSoap->error');
150                 $this->server->fault($errorObject->getFaultCode(), $errorObject->getName(), '', $errorObject->getDescription());
151                 $GLOBALS['log']->info('Begin: NusoapSoap->error');
152         } // fn
153         
154 } // clazz