- Timestamp:
- 2011/10/31 13:54:41 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_11-dev/data/module/SOAP/example/example_server.php
r21299 r21304 1 1 <?php 2 /** 3 * Example server. 4 * 5 * PHP versions 4 and 5 6 * 7 * LICENSE: This source file is subject to version 2.02 of the PHP license, 8 * that is bundled with this package in the file LICENSE, and is available at 9 * through the world-wide-web at http://www.php.net/license/2_02.txt. If you 10 * did not receive a copy of the PHP license and are unable to obtain it 11 * through the world-wide-web, please send a note to license@php.net so we can 12 * mail you a copy immediately. 13 * 14 * @category Web Services 15 * @package SOAP 16 * @author Shane Caraveo <Shane@Caraveo.com> Port to PEAR and more 17 * @author Jan Schneider <jan@horde.org> Maintenance 18 * @copyright 2003-2007 The PHP Group 19 * @license http://www.php.net/license/2_02.txt PHP License 2.02 20 * @link http://pear.php.net/package/SOAP 21 */ 2 // 3 // +----------------------------------------------------------------------+ 4 // | PHP Version 4 | 5 // +----------------------------------------------------------------------+ 6 // | Copyright (c) 1997-2003 The PHP Group | 7 // +----------------------------------------------------------------------+ 8 // | This source file is subject to version 2.02 of the PHP license, | 9 // | that is bundled with this package in the file LICENSE, and is | 10 // | available at through the world-wide-web at | 11 // | http://www.php.net/license/2_02.txt. | 12 // | If you did not receive a copy of the PHP license and are unable to | 13 // | obtain it through the world-wide-web, please send a note to | 14 // | license@php.net so we can mail you a copy immediately. | 15 // +----------------------------------------------------------------------+ 16 // | Authors: Shane Caraveo <Shane@Caraveo.com> | 17 // +----------------------------------------------------------------------+ 18 // 19 // $Id: example_server.php,v 1.6 2007/01/22 11:51:45 yunosh Exp $ 20 // 22 21 23 / ** SOAP_Value */22 // first, include the SOAP/Server class 24 23 require_once 'SOAP/Value.php'; 25 24 require_once 'SOAP/Fault.php'; 26 25 27 / ** SOAPStruct */28 require_once dirname(__FILE__) . '/example_types.php';26 // SOAPStruct is defined in the following file 27 require_once 'example_types.php'; 29 28 30 / * Create a class for your SOAP functions. */29 // create a class for your soap functions 31 30 class SOAP_Example_Server { 32 /* The dispatch map does not need to be used, but aids the server class in 33 * knowing what parameters are used with the functions. This is the ONLY 34 * way to have multiple OUT parameters. If you use a dispatch map, you 35 * MUST add ALL functions you wish to allow be called. If you do not use 36 * a dispatch map, then any public function can be called from SOAP. We 37 * consider this to be any function in the class unless it starts with 38 * underscore. If you do not define in/out parameters, the function can 39 * be called with parameters, but no validation on parameters will 40 * occur. */ 31 /** 32 * The dispactch map does not need to be used, but aids 33 * the server class in knowing what parameters are used 34 * with the functions. This is the ONLY way to have 35 * multiple OUT parameters. If you use a dispatch map, you 36 * MUST add ALL functions you wish to allow be called. If 37 * you do not use a dispatch map, then any public function 38 * can be called from soap (in php4, we consider this to be 39 * any function in the class unless it starts with underscore, 40 * php5 support is not complete yet in this regard). 41 * if you do not define in/out parameters, the function can be 42 * called with parameters, but no validation on parameters will 43 * occure. 44 */ 41 45 var $__dispatch_map = array(); 42 46 43 47 function SOAP_Example_Server() { 44 /* When generating WSDL for a server, you have to define any special 45 * complex types that you use (ie classes). Using a namespace id 46 * before the type will create an XML schema with the targetNamespace 47 * for the type multiple types with the same namespace will appear in 48 * the same schema section. Types with different namespaces will be 49 * in seperate schema sections. The following SOAPStruct typedef 50 * cooresponds to the SOAPStruct class above. */ 51 $this->__typedef['{http://soapinterop.org/xsd}SOAPStruct'] = 52 array('varString' => 'string', 53 'varInt' => 'int', 54 'varFloat' => 'float'); 48 /** 49 * when generating wsdl for a server, you have to define 50 * any special complex types that you use (ie classes). 51 * using a namespace id before the type will create an 52 * xml schema with the targetNamespace for the type 53 * multiple types with the same namespace will appear 54 * in the same schema section. types with different 55 * namespaces will be in seperate schema sections. 56 * the following SOAPStruct typedef cooresponds to the 57 * SOAPStruct class above. 58 */ 59 $this->__typedef['{http://soapinterop.org/xsd}SOAPStruct'] = 60 array( 61 'varString' => 'string', 62 'varInt' => 'int', 63 'varFloat' => 'float' 64 ); 55 65 56 / * An aliased function with multiple out parameters. */57 58 59 'out' => array('outputString' => 'string',60 'outputInteger' => 'int', 61 'outputFloat' => 'float'), 62 'alias' => 'myEchoStructAsSimpleTypes'); 63 $this->__dispatch_map['echoStringSimple'] = 64 array('in' => array('inputStringSimple' => 'string'),65 'out' => array('outputStringSimple' => 'string'));66 67 68 'out' => array('outputString' => 'string')); 69 $this->__dispatch_map['divide'] = 70 array('in' => array('dividend' => 'int', 71 72 'out' => array('outputFloat' => 'float')); 73 $this->__dispatch_map['echoStruct'] = 74 array('in' => array('inputStruct' => '{http://soapinterop.org/xsd}SOAPStruct'), 75 'out' => array('outputStruct' => '{http://soapinterop.org/xsd}SOAPStruct')); 76 77 $this->__dispatch_map['echoMimeAttachment'] = 78 array('in' => array('stuff' => 'string'), 79 'out' => array('outputMime' => 'string'));66 // an aliased function with multiple out parameters 67 $this->__dispatch_map['echoStructAsSimpleTypes'] = 68 array('in' => array('inputStruct' => '{http://soapinterop.org/xsd}SOAPStruct'), 69 'out' => array('outputString' => 'string', 'outputInteger' => 'int', 'outputFloat' => 'float'), 70 'alias' => 'myEchoStructAsSimpleTypes' 71 ); 72 $this->__dispatch_map['echoStringSimple'] = 73 array('in' => array('inputStringSimple' => 'string'), 74 'out' => array('outputStringSimple' => 'string'), 75 ); 76 $this->__dispatch_map['echoString'] = 77 array('in' => array('inputString' => 'string'), 78 'out' => array('outputString' => 'string'), 79 ); 80 $this->__dispatch_map['divide'] = 81 array('in' => array('dividend' => 'int', 'divisor' => 'int'), 82 'out' => array('outputFloat' => 'float'), 83 ); 84 $this->__dispatch_map['echoStruct'] = 85 array('in' => array('inputStruct' => '{http://soapinterop.org/xsd}SOAPStruct'), 86 'out' => array('outputStruct' => '{http://soapinterop.org/xsd}SOAPStruct'), 87 ); 88 89 $this->__dispatch_map['echoMimeAttachment'] = array(); 80 90 } 81 91 82 /* This private function is called on by SOAP_Server to determine any 83 * special dispatch information that might be necessary. This, for 84 * example, can be used to set up a dispatch map for functions that return 85 * multiple OUT parameters. */ 86 function __dispatch($methodname) 87 { 88 if (isset($this->__dispatch_map[$methodname])) { 92 /* this private function is called on by SOAP_Server to determine any 93 special dispatch information that might be necessary. This, for example, 94 can be used to set up a dispatch map for functions that return multiple 95 OUT parameters */ 96 function __dispatch($methodname) { 97 if (isset($this->__dispatch_map[$methodname])) 89 98 return $this->__dispatch_map[$methodname]; 90 } 91 return null; 99 return NULL; 92 100 } 93 101 94 / * A simple echoString function. */102 // a simple echoString function 95 103 function echoStringSimple($inputString) 96 104 { 97 105 return $inputString; 98 106 } 99 100 / * An explicit echoString function. */107 108 // an explicit echostring function 101 109 function echoString($inputString) 102 110 { 103 return new SOAP_Value('outputString', 'string',$inputString);111 return new SOAP_Value('outputString','string',$inputString); 104 112 } 105 113 106 114 function divide($dividend, $divisor) 107 115 { 108 / * The SOAP server would normally catch errors like this and return a109 * fault, but this is how you do it yourself. */110 if ($divisor == 0) {116 // the soap server would normally catch errors like this 117 // and return a fault, but this is how you do it yourself. 118 if ($divisor == 0) 111 119 return new SOAP_Fault('You cannot divide by zero', 'Client'); 112 } else {120 else 113 121 return $dividend / $divisor; 114 }115 122 } 116 123 … … 119 126 return $inputStruct->__to_soap('outputStruct'); 120 127 } 121 128 122 129 /** 123 * Takes a SOAPStruct as input, and returns each of its elements as OUT 124 * parameters. 130 * echoStructAsSimpleTypes 131 * takes a SOAPStruct as input, and returns each of its elements 132 * as OUT parameters 125 133 * 126 * This function is also aliased so you have to call it as127 * echoStructAsSimpleTypes .134 * this function is also aliased so you have to call it with 135 * echoStructAsSimpleTypes 128 136 * 129 137 * SOAPStruct is defined as: 130 * <code>138 * 131 139 * struct SOAPStruct: 132 140 * string varString 133 141 * integer varInt 134 142 * float varFloat 135 * </code>143 * 136 144 */ 137 145 function myEchoStructAsSimpleTypes($struct) 138 146 { 139 /* Convert a SOAPStruct to an array. */ 140 141 new SOAP_Value('outputString', 'string',$struct->varString),142 new SOAP_Value('outputInteger', 'int',$struct->varInt),143 new SOAP_Value('outputFloat', 'float',$struct->varFloat)147 # convert a SOAPStruct to an array 148 return array( 149 new SOAP_Value('outputString','string',$struct->varString), 150 new SOAP_Value('outputInteger','int',$struct->varInt), 151 new SOAP_Value('outputFloat','float',$struct->varFloat) 144 152 ); 145 153 } 146 154 147 155 function echoMimeAttachment($stuff) 148 156 { 149 return new SOAP_Attachment('return', 150 'application/octet-stream', 151 null, 152 $stuff); 153 } 157 return new SOAP_Attachment('return','application/octet-stream',NULL,$stuff); 158 } 159 } 154 160 155 } 161 ?>
Note: See TracChangeset
for help on using the changeset viewer.