forked from jk/php-wsdl-creator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class.phpwsdlparam.php
176 lines (163 loc) · 5.21 KB
/
class.phpwsdlparam.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
/*
PhpWsdl - Generate WSDL from PHP
Copyright (C) 2011 Andreas Müller-Saala, wan24.de
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 3 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, see <http://www.gnu.org/licenses/>.
*/
if(basename($_SERVER['SCRIPT_FILENAME'])==basename(__FILE__))
exit;
PhpWsdl::RegisterHook('InterpretKeywordparamHook','internal','PhpWsdlParam::InterpretParam');
PhpWsdl::RegisterHook('InterpretKeywordreturnHook','internal','PhpWsdlParam::InterpretReturn');
/**
* A parameter or return value definition for a method
*
* @author Andreas Müller-Saala, wan24.de
*/
class PhpWsdlParam extends PhpWsdlObject{
/**
* The parameter type name
*
* @var string
*/
public $Type;
/**
* Documentation
*
* @var string
*/
public $Docs=null;
/**
* The default name for the return value object
* Use %method% as placeholder for the method name
*
* @var string
*/
public static $DefaultReturnName='return';
/**
* Constructor
*
* @param string $name The name
* @param string $type Optional the type name (default: string)
* @param array $settings Optional the settings hash array (default: NULL)
*/
public function PhpWsdlParam($name,$type='string',$settings=null){
PhpWsdl::Debug('New parameter '.$name);
parent::PhpWsdlObject($name,$settings);
$this->Type=$type;
}
/**
* Create the part WSDL
*
* @param PhpWsdl $pw The PhpWsdl object
* @return string The WSDL
*/
public function CreatePart($pw){
PhpWsdl::Debug('Create WSDL definition for parameter part '.$this->Name);
$res='<wsdl:part name="'.$this->Name.'" type="';
$res.=PhpWsdl::TranslateType($this->Type).'"';
if($pw->IncludeDocs&&!$pw->Optimize&&!is_null($this->Docs)){
$res.='>'."\n";
$res.='<s:documentation><![CDATA['.$this->Docs.']]></s:documentation>'."\n";
$res.='</wsdl:part>';
}else{
$res.=' />';
}
return $res;
}
/**
* Create parameter HTML documentation
*
* @param array $data Some data
*/
public function CreateParamHtml($data){
PhpWsdl::Debug('CreateParamHtml for '.$data['param']->Name);
$res=&$data['res'];
$p=&$data['param'];
if(is_null($p->Docs))
return;
if(in_array($p->Type,PhpWsdl::$BasicTypes)){
$res[]='<li class="pre"><span class="blue">'.$p->Type.'</span> <span class="bold">'.$p->Name.'</span>';
}else{
$res[]='<li class="pre"><a href="#'.$p->Type.'"><span class="lightBlue">'.$p->Type.'</span></a> <span class="bold">'.$p->Name.'</span>';
}
$res[sizeof($res)-1].='<br><span class="normal">'.nl2br(htmlentities($p->Docs)).'</span></li>';
PhpWsdl::CallHook(
'CreateParameterHtmlHook',
$data
);
}
/**
* Create return value HTML documentation
*
* @param array $data Some data
*/
public function CreateReturnHtml($data){
PhpWsdl::Debug('CreateReturnHtml for '.$data['method']->Return->Name);
$res=&$data['res'];
$m=&$data['method'];
$res[]='<p>Return value <span class="pre">';
$o=sizeof($res)-1;
$type=$m->Return->Type;
if(in_array($type,PhpWsdl::$BasicTypes)){
$res[$o].='<span class="blue">'.$type.'</span>';
}else{
$res[$o].='<a href="#'.$type.'"><span class="lightBlue">'.$type.'</span></a>';
}
$res[$o].='</span>'.((!is_null($m->Return->Docs))?': '.nl2br(htmlentities($m->Return->Docs)):'').'</p>';
PhpWsdl::CallHook(
'CreateReturnHtmlHook',
$data
);
}
/**
* Interpret a parameter keyword
*
* @param array $data The parser data
* @return boolean Response
*/
public static function InterpretParam($data){
if($data['method']=='')
return true;
$info=explode(' ',$data['keyword'][1],3);
if(sizeof($info)<2)
return true;
$name=(substr($info[1],0,1)=='$')?substr($info[1],1):$info[1];
if(substr($name,strlen($name)-1,1)==';')
$name=substr($name,0,strlen($name)-1);
PhpWsdl::Debug('Interpret parameter '.$name);
if($data['server']->ParseDocs)
if(sizeof($info)>2)
$data['settings']['docs']=trim($info[2]);
$data['param'][]=new PhpWsdlParam($name,$info[0],$data['settings']);
$data['settings']=Array();
return false;
}
/**
* Interpret a return value
*
* @param array $data The parser data
* @return boolean Response
*/
public static function InterpretReturn($data){
if($data['method']=='')
return true;
$info=explode(' ',$data['keyword'][1],2);
if(sizeof($info)<1)
return true;
PhpWsdl::Debug('Interpret return');
if($data['server']->ParseDocs)
if(sizeof($info)>1)
$data['settings']['docs']=trim($info[1]);
$data['return']=new PhpWsdlParam(str_replace('%method%',$data['method'],self::$DefaultReturnName),$info[0],$data['settings']);
$data['settings']=Array();
return false;
}
}