MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
class.phpwsdlcomplex.php
Ir para a documentação deste ficheiro.
1<?php
2
3/*
4PhpWsdl - Generate WSDL from PHP
5Copyright (C) 2011 Andreas Zimmermann, wan24.de
6
7This program is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free Software
9Foundation; either version 3 of the License, or (at your option) any later
10version.
11
12This program is distributed in the hope that it will be useful, but WITHOUT
13ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License along with
17this program; if not, see <http://www.gnu.org/licenses/>.
18*/
19
20if(basename($_SERVER['SCRIPT_FILENAME'])==basename(__FILE__))
21 exit;
22
23PhpWsdl::RegisterHook('InterpretKeywordpw_complexHook','internal','PhpWsdlComplex::InterpretComplex');
24PhpWsdl::RegisterHook('CreateObjectHook','internalcomplex','PhpWsdlComplex::CreateComplexTypeObject');
25
37 public $Type=null;
43 public $Elements;
49 public $IsArray;
55 public static $DisableArrayPostfix=false;
56
64 public function PhpWsdlComplex($name,$el=Array(),$settings=null){
65 self::__construct($name, $el, $settings);
66 }
67
68 public function __construct($name,$el=Array(),$settings=null){
69 PhpWsdl::Debug('New complex type '.$name);
70 parent::__construct($name,$settings);
71 if(!self::$DisableArrayPostfix){
72 $this->IsArray=substr($name,strlen($name)-5,5)=='Array';
73 if($this->IsArray)
74 $this->Type=substr($this->Name,0,strlen($this->Name)-5);
75 }
76 $this->Elements=$el;
77 if(!is_null($settings))
78 if(isset($settings['isarray']))
79 $this->IsArray=$settings['isarray'];
80 }
81
88 public function CreateType($pw){
89 $res=Array();
90 $res[]='<s:complexType name="'.$this->Name.'">';
91 if($pw->IncludeDocs&&!$pw->Optimize&&!is_null($this->Docs)){
92 $res[]='<s:annotation>';
93 $res[]='<s:documentation><![CDATA['.$this->Docs.']]></s:documentation>';
94 $res[]='</s:annotation>';
95 }
96 if(!$this->IsArray){
97 PhpWsdl::Debug('Create WSDL definition for type '.$this->Name.' as type');
98 $res[]='<s:sequence>';
99 $i=-1;
100 $len=sizeof($this->Elements);
101 while(++$i<$len)
102 $res[]=$this->Elements[$i]->CreateElement($pw);
103 $res[]='</s:sequence>';
104 }else{
105 PhpWsdl::Debug('Create WSDL definition for type '.$this->Name.' as array');
106 $res[]='<s:complexContent>';
107 $res[]='<s:restriction base="soapenc:Array">';
108 $res[]='<s:attribute ref="soapenc:arrayType" wsdl:arrayType="';
109 $res[sizeof($res)-1].=(in_array($this->Type,PhpWsdl::$BasicTypes))?'s':'tns';
110 $res[sizeof($res)-1].=':'.$this->Type.'[]" />';
111 $res[]='</s:restriction>';
112 $res[]='</s:complexContent>';
113 }
114 $res[]='</s:complexType>';
115 return implode('',$res);
116 }
117
124 public function GetElement($name){
125 PhpWsdl::Debug('Find element '.$name);
126 $i=-1;
127 $len=sizeof($this->Elements);
128 while(++$i<$len)
129 if($this->Elements[$i]->Name==$name){
130 PhpWsdl::Debug('Found element at index '.$i);
131 return $this->Elements[$i];
132 }
133 return null;
134 }
135
141 public function CreateTypeHtml($data){
142 PhpWsdl::Debug('CreateTypeHtml for '.$data['type']->Name);
143 $res=&$data['res'];
144 $t=&$data['type'];
145 $res[]='<h3>'.$t->Name.'</h3>';
146 $res[]='<a name="'.$t->Name.'"></a>';
147 $eLen=sizeof($t->Elements);
148 if($t->IsArray){
149 // Array type
150 $res[]='<p>This is an array type of <span class="pre">';
151 $o=sizeof($res)-1;
152 if(in_array($t->Type,PhpWsdl::$BasicTypes)){
153 $res[$o].='<span class="blue">'.$t->Type.'</span>';
154 }else{
155 $res[$o].='<a href="#'.$t->Type.'"><span class="lightBlue">'.$t->Type.'</span></a>';
156 }
157 $res[$o].='</span>.</p>';
158 if(!is_null($t->Docs))
159 $res[]='<p>'.nl2br(htmlentities($t->Docs)).'</p>';
160 }else if($eLen>0){
161 // Complex type with elements
162 if(!is_null($t->Docs))
163 $res[]='<p>'.nl2br(htmlentities($t->Docs)).'</p>';
164 $res[]='<ul class="pre">';
165 $j=-1;
166 while(++$j<$eLen)
167 $t->Elements[$j]->CreateElementHtml(array_merge(
168 $data,
169 Array(
170 'element' => $t->Elements[$j]
171 )
172 ));
173 $res[]='</ul>';
174 }else{
175 // Complex type without elements
176 $res[]='<p>This type has no elements.</p>';
177 }
179 'CreateTypeHtmlHook',
180 $data
181 );
182 }
183
189 public function CreateTypePhp($data){
190 if($this->IsArray)
191 return;
192 $server=$data['server'];
193 $res=&$data['res'];
194 $res[]="/**";
195 if(!is_null($this->Docs)){
196 $res[]=" * ".implode("\n * ",explode("\n",$this->Docs));
197 $res[]=" *";
198 }
199 $i=-1;
200 $eLen=sizeof($this->Elements);
201 while(++$i<$eLen){
202 $e=$this->Elements[$i];
203 $res[]=" * @pw_element ".$e->Type." \$".$e->Name.((!is_null($e->Docs))?" ".implode("\n\t * ",explode("\n",$e->Docs)):"");
204 }
205 $res[]=" * @pw_complex ".$this->Name;
206 $res[]=" */";
207 $res[]="class ".$this->Name."{";
208 $i=-1;
209 while(++$i<$eLen){
210 $e=$this->Elements[$i];
211 $res[]="\t/**";
212 if(!is_null($e->Docs)){
213 $res[]="\t * ".implode("\n\t * ",explode("\n",$e->Docs));
214 $res[]="\t *";
215 }
216 $res[]="\t * @var ".$e->Type;
217 $res[]="\t */";
218 $res[]="\tpublic \$".$this->Elements[$i]->Name.";";
219 }
220 $res[]="}";
221 }
222
229 public static function InterpretComplex($data){
230 $info=explode(' ',$data['keyword'][1],3);
231 if(sizeof($info)<1)
232 return true;
233 $server=$data['server'];
234 $name=$info[0];
235 PhpWsdl::Debug('Interpret complex type "'.$name.'"');
236 $type=null;
237 $docs=null;
238 if(strpos($name,'[]')>-1){
239 if(sizeof($info)<2){
240 PhpWsdl::Debug('WARNING: Invalid array definition!');
241 return true;
242 }
243 $name=substr($name,0,strlen($name)-2);
244 if(!is_null($server->GetType($name))){
245 PhpWsdl::Debug('WARNING: Double type detected!');
246 return true;
247 }
248 $type=$info[1];
249 if($server->ParseDocs)
250 if(sizeof($info)>2)
251 $docs=$info[2];
252 PhpWsdl::Debug('Array "'.$name.'" type of "'.$type.'" definition');
253 }else{
254 if(!is_null($server->GetType($name))){
255 PhpWsdl::Debug('WARNING: Double type detected!');
256 return true;
257 }
258 if(!self::$DisableArrayPostfix&&substr($name,strlen($name)-5)=='Array'){
259 $type=substr($name,0,strlen($name)-5);
260 PhpWsdl::Debug('Array "'.$name.'" type of "'.$type.'" definition');
261 }else{
262 PhpWsdl::Debug('Complex type definition');
263 }
264 if($server->ParseDocs){
265 $temp=sizeof($info);
266 if($temp>1)
267 $docs=($temp>2)?$info[1].' '.$info[2]:$info[1];
268 }
269 }
270 $data['type']=Array(
271 'id' => 'complex',
272 'name' => $name,
273 'type' => $type,
274 'docs' => $docs
275 );
276 return false;
277 }
278
285 public static function CreateComplexTypeObject($data){
286 if($data['method']!='')
287 return true;
288 if(!is_null($data['obj']))
289 return true;
290 if(!is_array($data['type']))
291 return true;
292 if(!isset($data['type']['id']))
293 return true;
294 if($data['type']['id']!='complex')
295 return true;
296 if(!is_null($data['docs'])){
297 $data['settings']['docs']=$data['docs'];
298 }else{
299 $data['settings']['docs']=$data['type']['docs'];
300 }
301 PhpWsdl::Debug('Add complex type '.$data['type']['name']);
302 $data['settings']['isarray']=!is_null($data['type']['type']);
303 $data['obj']=new PhpWsdlComplex($data['type']['name'],$data['elements'],$data['settings']);
304 $data['obj']->Type=$data['type']['type'];
305 $data['settings']=Array();
306 $data['server']->Types[]=$data['obj'];
307 return true;
308 }
309}
static CreateComplexTypeObject($data)
static InterpretComplex($data)
__construct($name, $el=Array(), $settings=null)
PhpWsdlComplex($name, $el=Array(), $settings=null)
static Debug($str)
static RegisterHook($hook, $name, $data)
static $BasicTypes
static CallHook($name, $data=null)