source: branches/feature-module-update/data/module/SOAP/example/example_server.php @ 16957

Revision 16957, 6.2 KB checked in by naka, 15 years ago (diff)

PEAR::SOAPモジュールアップ

Line 
1<?php
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//
21
22// first, include the SOAP/Server class
23require_once 'SOAP/Value.php';
24require_once 'SOAP/Fault.php';
25
26// SOAPStruct is defined in the following file
27require_once 'example_types.php';
28
29// create a class for your soap functions
30class SOAP_Example_Server {
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     */
45    var $__dispatch_map = array();
46
47    function SOAP_Example_Server() {
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                         );
65
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();
90    }
91
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]))
98            return $this->__dispatch_map[$methodname];
99        return NULL;
100    }
101
102    // a simple echoString function
103    function echoStringSimple($inputString)
104    {
105    return $inputString;
106    }
107   
108    // an explicit echostring function
109    function echoString($inputString)
110    {
111    return new SOAP_Value('outputString','string',$inputString);
112    }
113
114    function divide($dividend, $divisor)
115    {
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)
119            return new SOAP_Fault('You cannot divide by zero', 'Client');
120        else
121            return $dividend / $divisor;
122    }
123
124    function echoStruct($inputStruct)
125    {
126        return $inputStruct->__to_soap('outputStruct');
127    }
128   
129    /**
130     * echoStructAsSimpleTypes
131     * takes a SOAPStruct as input, and returns each of its elements
132     * as OUT parameters
133     *
134     * this function is also aliased so you have to call it with
135     * echoStructAsSimpleTypes
136     *
137     * SOAPStruct is defined as:
138     *
139     * struct SOAPStruct:
140     *    string varString
141     *    integer varInt
142     *    float varFloat
143     *
144     */
145    function myEchoStructAsSimpleTypes($struct)
146    {
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)
152        );
153    }
154   
155    function echoMimeAttachment($stuff)
156    {
157        return new SOAP_Attachment('return','application/octet-stream',NULL,$stuff);
158    }   
159}
160
161?>
Note: See TracBrowser for help on using the repository browser.