Ignore:
Timestamp:
2012/01/17 16:32:25 (12 years ago)
Author:
Seasoft
Message:

2.12系へマイルストーン変更となったチケット分を差し戻し
r21326 #1536
r21325 #1528
r21324 #1547,#1546
r21323 #1546
r21322 #1543
r21321 #1536
r21320 #1536
r21319 #1544
r21318 #1521,#1522
r21317 #1431

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_11-dev/data/module/SOAP/example/disco_server.php

    r21318 r21410  
    11<?php 
    2 /** 
    3  * This example shows how to mark up a server object so that WSDL files may be 
    4  * dynamicaly generated by the SOAP server.  This also provides access to a 
    5  * generated DISCO document.  The fact that this example has an MP3 class is 
    6  * in no way related to DISCO. ;) 
    7  * 
    8  * DISCO: http://msdn.microsoft.com/msdnmag/issues/02/02/xml/default.aspx 
    9  * 
    10  * Urls accessing this server would look like: 
    11  * - http://localhost/disco_server.php?wsdl (generate WSDL file) 
    12  * - http://localhost/disco_server.php (GET request generates DISCO) 
    13  * - http://localhost/disco_server.php (POST for normal SOAP requests) 
    14  * 
    15  * PHP versions 4 and 5 
    16  * 
    17  * LICENSE: This source file is subject to version 2.02 of the PHP license, 
    18  * that is bundled with this package in the file LICENSE, and is available at 
    19  * through the world-wide-web at http://www.php.net/license/2_02.txt.  If you 
    20  * did not receive a copy of the PHP license and are unable to obtain it 
    21  * through the world-wide-web, please send a note to license@php.net so we can 
    22  * mail you a copy immediately. 
    23  * 
    24  * @category   Web Services 
    25  * @package    SOAP 
    26  * @author     Shane Caraveo <Shane@Caraveo.com>   Port to PEAR and more 
    27  * @author     Jan Schneider <jan@horde.org>       Maintenance 
    28  * @copyright  2003-2007 The PHP Group 
    29  * @license    http://www.php.net/license/2_02.txt  PHP License 2.02 
    30  * @link       http://pear.php.net/package/SOAP 
    31  */ 
     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// | Author: Dmitri Vinogradov <dimitri@vinogradov.de>                    | 
     17// +----------------------------------------------------------------------+ 
     18// 
     19// $Id: disco_server.php,v 1.6 2006/12/27 10:50:39 arnaud Exp $ 
     20 
     21/* 
     22  This example shows how to mark up a server object so that 
     23  wsdl files may be dynamicaly generated by the soap 
     24  server.  This also provides access to a generated DISCO document. 
     25  The fact that this example has an MP3 class is in no way 
     26  related to DISCO. ;) 
     27   
     28  DISCO: http://msdn.microsoft.com/msdnmag/issues/02/02/xml/default.aspx 
     29   
     30  A url accessing this server would look like: 
     31   
     32  http://localhost/disco_server.php?wsdl (generate WSDL file) 
     33  http://localhost/disco_server.php (GET request generates DISCO) 
     34  http://localhost/disco_server.php (POST for normal soap requests) 
     35*/ 
    3236 
    3337error_reporting(E_ALL); 
    34  
    35 /** SOAP_Server */ 
    3638require_once 'SOAP/Server.php'; 
    3739 
    38 /** 
    39  * MP3 database class. 
    40  * 
    41  * @package SOAP 
    42  */ 
    43 class MP3DB_Class 
    44 { 
    45  
     40class MP3DB_Class { 
    4641    var $__dispatch_map = array(); 
    47     var $__typedef = array(); 
    48  
    49     function MP3DB_Class() 
    50     { 
    51         /* The only way to describe all methods in WSDL (messages, 
    52          * PortType-operations and bindings) is to use __dispatch_map to 
    53          * describe every method (even methods using simple data types in 'in' 
    54          * and 'out' parameters...) */ 
     42    var $__typedef     = array(); 
     43     
     44    function MP3DB_Class () { 
     45        /** 
     46        * the only way to describe all methods in WSDL (messages, 
     47        * PortType-operations and bindings) is to use __dispatch_map 
     48        * to describe every method (even methods using simple data  
     49        * types in 'in' and 'out' parameters...) 
     50        */ 
     51         
    5552        $this->__dispatch_map['SayHallo'] = 
    56             array('in' => array('input' => 'string'), 
    57                   'out' => array('return' => 'string')); 
     53                    array( 
     54                        'in' => array('input' => 'string'), 
     55                        'out' => array('return' => 'string') 
     56                    ); 
     57                     
    5858        $this->__dispatch_map['SayThisNTimes'] = 
    59             array('in' => array('SayThis'=>'string','NTimes' => 'int'), 
    60                   'out' => array('return' => '{urn:MP3DB}ArrayOfStrings')); 
     59                    array( 
     60                        'in' => array('SayThis'=>'string','NTimes' => 'int'), 
     61                        'out' => array('return' => '{urn:MP3DB}ArrayOfStrings') 
     62                    ); 
     63                     
    6164        $this->__dispatch_map['GetMP3Tracks'] = 
    62             array('in' => array('query' => 'string'), 
    63                   'out' => array('return' => '{urn:MP3DB}GetMP3TracksResult')); 
     65                    array( 
     66                        'in' => array('query' => 'string'), 
     67                        'out' => array('return' => '{urn:MP3DB}GetMP3TracksResult') 
     68                    ); 
     69                     
    6470        $this->__dispatch_map['AddMP3Track'] = 
    65             array('in' => array('MP3Track' => '{urn:MP3DB}MP3Track'), 
    66                   'out' => array('return' => '{urn:MP3DB}AddMP3TrackResult')); 
    67  
    68         /* Use __typedef to describe userdefined Types in WSDL.  Structs and 
    69          * one-dimensional arrays are supported. 
    70          * 
    71          * Struct example: 
    72          * $this->__typedef['TypeName'] = array('VarName' => 'xsdType', ... ); 
    73          * or 
    74          * $this->__typedef['TypeName'] = array('VarName' => '{namespace}SomeOtherType'); 
    75          * 
    76          * Array example: 
    77          * $this->__typedef['TypeName'] = array(array('item' => 'xsdType')); 
    78          * or 
    79          * $this->__typedef['TypeName'] = array(array('item' => '{namespace}SomeOtherType')); 
    80          */ 
    81  
    82         /* Struct 'MP3Track'. */ 
    83         $this->__typedef['MP3Track'] = 
    84             array('Title' => 'string', 
    85                   'Artist' => 'string', 
    86                   'Album' => 'string', 
    87                   'Year' => 'int', 
    88                   'Genre' => 'int', 
    89                   'Comment' => 'string', 
    90                   'Composer' => 'string', 
    91                   'Orig_Artist' => 'string', 
    92                   'URL' => 'string', 
    93                   'Encoded_by' => 'string'); 
    94  
    95         /* MP3TracksArray - array of 'MP3Track' structs. */ 
    96         $this->__typedef['MP3TracksArray'] = 
    97             array(array('item' => '{urn:MP3DB}MP3Track')); 
    98  
    99         /* Struct 'MethodDebug'. */ 
    100         $this->__typedef['MethodDebug'] = 
    101             array('rc' => 'boolean', 
    102                   'ErrNo' => 'int', 
    103                   'Error' => 'string'); 
    104  
    105         /* Return Struct of method GetMP3Tracks. */ 
    106         $this->__typedef['GetMP3TracksResult'] = 
    107             array('MethodDebug' => '{urn:MP3DB}MethodDebug', 
    108                   'MP3Tracks' => '{urn:MP3DB}MP3TracksArray'); 
    109  
    110         /* Return Struct of method AddMP3Track. */ 
    111         $this->__typedef['AddMP3TrackResult'] = 
    112             array('MethodDebug' => '{urn:MP3DB}MethodDebug'); 
    113  
    114         /* Array of strings. */ 
    115         $this->__typedef['ArrayOfStrings'] = 
    116             array(array('item'=>'string')); 
    117     } 
    118  
    119     function SayHallo($name) 
    120     { 
    121         return 'Hello, ' . $name; 
    122     } 
    123  
    124  
    125     function SayThisNTimes($SayThis, $NTimes) 
    126     { 
     71                    array( 
     72                        'in' => array('MP3Track' => '{urn:MP3DB}MP3Track'), 
     73                        'out' => array('return' => '{urn:MP3DB}AddMP3TrackResult') 
     74                    ); 
     75 
     76        /** 
     77        * I use __typedef to describe userdefined Types in WSDL. 
     78        * Structs and one-dimensional arrays are supported: 
     79        * Struct example: $this->__typedef['TypeName'] = array('VarName' => 'xsdType', ... ); 
     80        *    or $this->__typedef['TypeName'] = array('VarName' => '{namespace}SomeOtherType'); 
     81        * Array example: $this->__typedef['TypeName'] = array(array('item' => 'xsdType')); 
     82        *    or $this->__typedef['TypeName'] = array(array('item' => '{namespace}SomeOtherType')); 
     83        */ 
     84     
     85        /** 
     86        * Struct 'MP3Track' 
     87        */ 
     88        $this->__typedef['MP3Track'] =  
     89                    array( 
     90                        'Title' => 'string', 
     91                        'Artist' => 'string',  
     92                        'Album' => 'string',  
     93                        'Year' => 'int',  
     94                        'Genre' => 'int', 
     95                        'Comment' => 'string', 
     96                        'Composer' => 'string', 
     97                        'Orig_Artist' => 'string', 
     98                        'URL' => 'string', 
     99                        'Encoded_by' => 'string' 
     100                    ); 
     101                     
     102                     
     103                     
     104        /** 
     105        * MP3TracksArray - array of 'MP3Track' structs 
     106        */ 
     107        $this->__typedef['MP3TracksArray'] =  
     108                    array( 
     109                        array( 
     110                            'item' => '{urn:MP3DB}MP3Track' 
     111                        ) 
     112                    ); 
     113                     
     114        /** 
     115        * Struct 'MethodDebug' 
     116        */ 
     117        $this->__typedef['MethodDebug'] =  
     118                    array( 
     119                        'rc' => 'boolean', 
     120                        'ErrNo' => 'int',  
     121                        'Error' => 'string' 
     122                    ); 
     123                     
     124        /** 
     125        * return Struct of method GetMP3Tracks 
     126        */ 
     127        $this->__typedef['GetMP3TracksResult'] =  
     128                    array( 
     129                        'MethodDebug' => '{urn:MP3DB}MethodDebug', 
     130                        'MP3Tracks' => '{urn:MP3DB}MP3TracksArray' 
     131                    ); 
     132                     
     133        /** 
     134        * return Struct of method AddMP3Track 
     135        */ 
     136        $this->__typedef['AddMP3TrackResult'] =  
     137                    array( 
     138                        'MethodDebug' => '{urn:MP3DB}MethodDebug' 
     139                    ); 
     140                     
     141        /** 
     142        * Array of strings 
     143        */ 
     144        $this->__typedef['ArrayOfStrings'] =  
     145                    array( 
     146                        array('item'=>'string') 
     147                    ); 
     148     
     149    } 
     150     
     151     
     152    function SayHallo($name) { 
     153        return "Hallo, " . $name; 
     154    } 
     155     
     156     
     157    function SayThisNTimes($SayThis,$NTimes) { 
    127158        for ($i = 0; $i < $NTimes; $i++) { 
    128             $return[$i] = $SayThis . ' ' . $i; 
     159            $return[$i] = $SayThis . " $i"; 
    129160        } 
    130         return new SOAP_Value('return', '{urn:MP3DB}ArrayOfStrings', $return); 
    131     } 
    132  
    133     function GetMP3Tracks($query = '') 
    134     { 
    135         for ($i = 0; $i < 5; $i++) { 
     161        return new SOAP_Value('return','{urn:MP3DB}ArrayOfStrings',$return); 
     162    } 
     163     
     164     
     165    function GetMP3Tracks($query = "") { 
     166        for($i = 0; $i < 5; $i++) { 
    136167            $this->MP3Tracks[$i] = new SOAP_Value( 
    137                 'item', 
    138                 '{urn:MP3DB}MP3Track', 
    139                 array('Title'       => new SOAP_Value('Title', 'string', 'some track $i'), 
    140                       'Artist'      => new SOAP_Value('Artist', 'string', 'some artist $i'), 
    141                       'Album'       => new SOAP_Value('Album', 'string', 'some album $i'), 
    142                       'Year'        => new SOAP_Value('Year', 'int', 1999), 
    143                       'Genre'       => new SOAP_Value('Genre', 'int', 100), 
    144                       'Comment'     => new SOAP_Value('Comment', 'string', 'blabla $i'), 
    145                       'Composer'    => new SOAP_Value('Composer', 'string', ''), 
    146                       'Orig_Artist' => new SOAP_Value('Orig_Artist', 'string', ''), 
    147                       'URL'         => new SOAP_Value('URL', 'string', ''), 
    148                       'Encoded_by'  => new SOAP_Value('Encoded_by', 'string', ''))); 
     168                    'item', 
     169                    '{urn:MP3DB}MP3Track', 
     170                    array( 
     171                        "Title"         => new SOAP_Value("Title","string","some track $i"), 
     172                        "Artist"        => new SOAP_Value("Artist","string","some artist $i"), 
     173                        "Album"         => new SOAP_Value("Album","string","some album $i"), 
     174                        "Year"          => new SOAP_Value("Year","int",(integer)1999), 
     175                        "Genre"         => new SOAP_Value("Genre","int",(integer)100), 
     176                        "Comment"       => new SOAP_Value("Comment","string","blabla $i"), 
     177                        "Composer"      => new SOAP_Value("Composer","string",""), 
     178                        "Orig_Artist"   => new SOAP_Value("Orig_Artist","string",""), 
     179                        "URL"           => new SOAP_Value("URL","string",""), 
     180                        "Encoded_by"    => new SOAP_Value("Encoded_by","string","") 
     181                        ) 
     182                ); 
    149183        } 
    150  
    151         $MethodDebug['rc']    = new SOAP_Value('rc', 'boolean', true); 
    152         $MethodDebug['ErrNo'] = new SOAP_Value('ErrNo', 'int', 0); 
    153         $MethodDebug['Error'] = new SOAP_Value('Error', 'string', ''); 
    154  
    155         return new SOAP_Value( 
    156             'return', 
    157             '{urn:MP3DB}GetMP3TracksResult', 
    158             array('MethodDebug' => new SOAP_Value('MethodDebug', '{urn:MP3DB}MethodDebug',$MethodDebug), 
    159                   'MP3Tracks'   => new SOAP_Value('MP3Tracks', '{urn:MP3DB}MP3TracksArray',$this->MP3Tracks))); 
    160     } 
    161  
    162     function AddMP3Track($MP3Track) 
    163     { 
    164         /* Well, let's imagine here some code for adding given mp3track to db 
    165          * or whatever... */ 
    166         $MethodDebug['rc']    = new SOAP_Value('rc', 'boolean', true); 
    167         $MethodDebug['ErrNo'] = new SOAP_Value('ErrNo', 'int', 0); 
    168         $MethodDebug['Error'] = new SOAP_Value('Error', 'string', ''); 
    169  
    170         return new SOAP_Value( 
    171             'return', 
    172             '{urn:MP3DB}AddMP3TrackResult', 
    173             array('MethodDebug' => new SOAP_Value('MethodDebug', '{urn:MP3DB}MethodDebug', $MethodDebug))); 
    174     } 
    175  
    176     function __dispatch($methodname) 
    177     { 
    178         if (isset($this->__dispatch_map[$methodname])) { 
     184         
     185        $MethodDebug["rc"]    = new SOAP_Value("rc","boolean",true); 
     186        $MethodDebug["ErrNo"] = new SOAP_Value("ErrNo","int",(integer)0); 
     187        $MethodDebug["Error"] = new SOAP_Value("Error","string",""); 
     188             
     189        return new SOAP_Value('return','{urn:MP3DB}GetMP3TracksResult',array( 
     190                    "MethodDebug" => new SOAP_Value('MethodDebug','{urn:MP3DB}MethodDebug',$MethodDebug), 
     191                    "MP3Tracks"   => new SOAP_Value('MP3Tracks','{urn:MP3DB}MP3TracksArray',$this->MP3Tracks) 
     192                    ) 
     193                ); 
     194    } 
     195     
     196     
     197    function AddMP3Track($MP3Track) { 
     198        # well, lets imagine here some code for adding given mp3track to db or whatever... 
     199        $MethodDebug["rc"]    = new SOAP_Value("rc","boolean",true); 
     200        $MethodDebug["ErrNo"] = new SOAP_Value("ErrNo","int",(integer)0); 
     201        $MethodDebug["Error"] = new SOAP_Value("Error","string",""); 
     202         
     203        return new SOAP_Value('return','{urn:MP3DB}AddMP3TrackResult',array( 
     204                    "MethodDebug" => new SOAP_Value('MethodDebug','{urn:MP3DB}MethodDebug',$MethodDebug) 
     205                    ) 
     206                ); 
     207    } 
     208     
     209     
     210    function __dispatch($methodname) { 
     211        if (isset($this->__dispatch_map[$methodname])) 
    179212            return $this->__dispatch_map[$methodname]; 
    180         } 
    181         return null; 
    182     } 
    183  
     213        return NULL; 
     214    } 
    184215} 
    185216 
    186 $server = new SOAP_Server(); 
     217$server = new SOAP_Server; 
    187218$server->_auto_translation = true; 
    188219$MP3DB_Class = new MP3DB_Class(); 
    189 $server->addObjectMap($MP3DB_Class, 'urn:MP3DB'); 
     220$server->addObjectMap($MP3DB_Class,'urn:MP3DB'); 
     221 
    190222 
    191223if (isset($_SERVER['REQUEST_METHOD']) && 
    192     $_SERVER['REQUEST_METHOD'] == 'POST') { 
     224    $_SERVER['REQUEST_METHOD']=='POST') { 
    193225    $server->service($HTTP_RAW_POST_DATA); 
    194226} else { 
    195227    require_once 'SOAP/Disco.php'; 
    196     $disco = new SOAP_DISCO_Server($server, 'MP3DB'); 
    197     header('Content-type: text/xml'); 
     228    $disco = new SOAP_DISCO_Server($server,"MP3DB"); 
     229    header("Content-type: text/xml"); 
    198230    if (isset($_SERVER['QUERY_STRING']) && 
    199         strpos($_SERVER['QUERY_STRING'], 'wsdl') !== false) { 
     231       strcasecmp($_SERVER['QUERY_STRING'],'wsdl')==0) { 
    200232        echo $disco->getWSDL(); 
    201233    } else { 
    202234        echo $disco->getDISCO(); 
    203235    } 
     236    exit; 
    204237} 
     238?> 
Note: See TracChangeset for help on using the changeset viewer.