| 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 [email protected] so we can |
|---|
| 12 | * mail you a copy immediately. |
|---|
| 13 | * |
|---|
| 14 | * @category Web Services |
|---|
| 15 | * @package SOAP |
|---|
| 16 | * @author Shane Caraveo <[email protected]> Port to PEAR and more |
|---|
| 17 | * @author Jan Schneider <[email protected]> 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 | */ |
|---|
| 22 | |
|---|
| 23 | /** SOAP_Value */ |
|---|
| 24 | require_once 'SOAP/Value.php'; |
|---|
| 25 | require_once 'SOAP/Fault.php'; |
|---|
| 26 | |
|---|
| 27 | /** SOAPStruct */ |
|---|
| 28 | require_once dirname(__FILE__) . '/example_types.php'; |
|---|
| 29 | |
|---|
| 30 | /* Create a class for your SOAP functions. */ |
|---|
| 31 | 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. */ |
|---|
| 41 | var $__dispatch_map = array(); |
|---|
| 42 | |
|---|
| 43 | 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'); |
|---|
| 55 | |
|---|
| 56 | /* An aliased function with multiple out parameters. */ |
|---|
| 57 | $this->__dispatch_map['echoStructAsSimpleTypes'] = |
|---|
| 58 | array('in' => array('inputStruct' => '{http://soapinterop.org/xsd}SOAPStruct'), |
|---|
| 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 | $this->__dispatch_map['echoString'] = |
|---|
| 67 | array('in' => array('inputString' => 'string'), |
|---|
| 68 | 'out' => array('outputString' => 'string')); |
|---|
| 69 | $this->__dispatch_map['divide'] = |
|---|
| 70 | array('in' => array('dividend' => 'int', |
|---|
| 71 | 'divisor' => 'int'), |
|---|
| 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')); |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 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])) { |
|---|
| 89 | return $this->__dispatch_map[$methodname]; |
|---|
| 90 | } |
|---|
| 91 | return null; |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | /* A simple echoString function. */ |
|---|
| 95 | function echoStringSimple($inputString) |
|---|
| 96 | { |
|---|
| 97 | return $inputString; |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | /* An explicit echoString function. */ |
|---|
| 101 | function echoString($inputString) |
|---|
| 102 | { |
|---|
| 103 | return new SOAP_Value('outputString', 'string', $inputString); |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | function divide($dividend, $divisor) |
|---|
| 107 | { |
|---|
| 108 | /* The SOAP server would normally catch errors like this and return a |
|---|
| 109 | * fault, but this is how you do it yourself. */ |
|---|
| 110 | if ($divisor == 0) { |
|---|
| 111 | return new SOAP_Fault('You cannot divide by zero', 'Client'); |
|---|
| 112 | } else { |
|---|
| 113 | return $dividend / $divisor; |
|---|
| 114 | } |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | function echoStruct($inputStruct) |
|---|
| 118 | { |
|---|
| 119 | return $inputStruct->__to_soap('outputStruct'); |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | /** |
|---|
| 123 | * Takes a SOAPStruct as input, and returns each of its elements as OUT |
|---|
| 124 | * parameters. |
|---|
| 125 | * |
|---|
| 126 | * This function is also aliased so you have to call it as |
|---|
| 127 | * echoStructAsSimpleTypes. |
|---|
| 128 | * |
|---|
| 129 | * SOAPStruct is defined as: |
|---|
| 130 | * <code> |
|---|
| 131 | * struct SOAPStruct: |
|---|
| 132 | * string varString |
|---|
| 133 | * integer varInt |
|---|
| 134 | * float varFloat |
|---|
| 135 | * </code> |
|---|
| 136 | */ |
|---|
| 137 | function myEchoStructAsSimpleTypes($struct) |
|---|
| 138 | { |
|---|
| 139 | /* Convert a SOAPStruct to an array. */ |
|---|
| 140 | return array( |
|---|
| 141 | new SOAP_Value('outputString', 'string', $struct->varString), |
|---|
| 142 | new SOAP_Value('outputInteger', 'int', $struct->varInt), |
|---|
| 143 | new SOAP_Value('outputFloat', 'float', $struct->varFloat) |
|---|
| 144 | ); |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | function echoMimeAttachment($stuff) |
|---|
| 148 | { |
|---|
| 149 | return new SOAP_Attachment('return', |
|---|
| 150 | 'application/octet-stream', |
|---|
| 151 | null, |
|---|
| 152 | $stuff); |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | } |
|---|