-
Notifications
You must be signed in to change notification settings - Fork 0
/
class.phpwsdl.php
2853 lines (2775 loc) · 77.9 KB
/
class.phpwsdl.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?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;
// Debugging
/*PhpWsdl::$Debugging=true;// Enable debugging
PhpWsdl::$DebugFile='./cache/debug.log';// The logfile to write the debugging messages to
PhpWsdl::$DebugBackTrace=false;// Include backtrace information in debugging messages?*/
// Initialize PhpWsdl
PhpWsdl::Init();
// You don't require class.phpwsdlelement.php and class.phpwsdlcomplex.php,
// as long as you don't use complex types. So you may comment those two
// requires out.
// You may also disable loading the class.phpwsdlproxy.php, if you don't plan
// to use the proxy class for your webservice.
require_once(dirname(__FILE__).'/class.phpwsdlformatter.php');
require_once(dirname(__FILE__).'/class.phpwsdlobject.php');
require_once(dirname(__FILE__).'/class.phpwsdlparser.php');
require_once(dirname(__FILE__).'/class.phpwsdlproxy.php');
require_once(dirname(__FILE__).'/class.phpwsdlparam.php');
require_once(dirname(__FILE__).'/class.phpwsdlmethod.php');
require_once(dirname(__FILE__).'/class.phpwsdlelement.php');
require_once(dirname(__FILE__).'/class.phpwsdlcomplex.php');
require_once(dirname(__FILE__).'/class.phpwsdlenum.php');
// Do things after the environment is configured
PhpWsdl::PostInit();
/**
* PhpWsdl class
*
* @author Andreas Müller-Saala
* @copyright ©2011 Andreas Müller-Saala, wan24.de
* @version 2.4
*/
class PhpWsdl{
/**
* The version number
*
* @var string
*/
public static $VERSION='2.4';
/**
* Set this to TRUE to enable the autorun in quick mode
*
* @var boolean
*/
public static $AutoRun=false;
/**
* Global static configuration
*
* @var array
*/
public static $Config=Array();
/**
* The webservice handler object
*
* @var object
*/
public static $ProxyObject=null;
/**
* The current PhpWsdl server
*
* @var PhpWsdl
*/
public static $ProxyServer=null;
/**
* Use WSDL with the proxy
*
* @var boolean
*/
public static $UseProxyWsdl=false;
/**
* Type encoding settings
*
* @var array
*/
public static $TypeEncoding=null;
/**
* Encode return values when using the proxy class?
* Note: All encoding have to be defined in the PhpWsdl::$TypeEncoding
*
* @var boolean
*/
public static $EncodeProxyReturn=false;
/**
* The name
*
* @var string
*/
public $Name;
/**
* Documentation
*
* @var string
*/
public $Docs=null;
/**
* The namespace
*
* @var string
*/
public $NameSpace=null;
/**
* The SOAP endpoint URI
*
* @var string
*/
public $EndPoint=null;
/**
* Set this to the WSDL URI, if it's different from your SOAP endpoint + "?WSDL"
*
* @var string
*/
public $WsdlUri=null;
/**
* Set this to the PHP URI, if it's different from your SOAP endpoint + "?PHPSOAPCLIENT"
*
* @var string
*/
public $PhpUri=null;
/**
* Set this to the HTML documentation URI, if it's different from your SOAP endpoint
*
* @var string
*/
public $DocUri=null;
/**
* The options for the PHP SoapServer
* Note: "actor" and "uri" will be set at runtime
*
* @var array
*/
public $SoapServerOptions=null;
/**
* An array of file names to parse
*
* @var string[]
*/
public $Files=Array();
/**
* An array of complex types
*
* @var PhpWsdlComplex[]
*/
public $Types=null;
/**
* An array of method
*
* @var PhpWsdlMethod[]
*/
public $Methods=null;
/**
* Remove tabs and line breaks?
* Note: Unoptimized WSDL won't be cached
*
* @var boolean
*/
public $Optimize=true;
/**
* UTF-8 encoded WSDL from the last CreateWsdl method call
*
* @var string
*/
public $WSDL=null;
/**
* Create a webservice handler class at runtime?
*
* @var boolean
*/
public $CreateHandler=false;
/**
* The created handler class
*
* @var PhpWsdlHandler
*/
public $Handler=null;
/**
* The handler class PHP code
*
* @var string
*/
public $HandlerPhp=null;
/**
* UTF-8 encoded HTML from the last OutputHtml method call
*
* @var string
*/
public $HTML=null;
/**
* UTF-8 encoded PHP from the last OutputPhp method call
*
* @var string
*/
public $PHP=null;
/**
* An array of basic types (these are just some of the XSD defined types
* (see http://www.w3.org/TR/2001/PR-xmlschema-2-20010330/)
*
* @var string[]
*/
public static $BasicTypes=Array(
'anyType',
'anyURI',
'base64Binary',
'boolean',
'byte',
'date',
'decimal',
'double',
'duration',
'dateTime',
'float',
'gDay',
'gMonth',
'gMonthDay',
'gYearMonth',
'gYear',
'hexBinary',
'int',
'integer',
'long',
'NOTATION',
'number',
'QName',
'short',
'string',
'time'
);
/**
* A list of non-nillable types
*
* @var string[]
*/
public static $NonNillable=Array(
'boolean',
'decimal',
'double',
'float',
'int',
'integer',
'long',
'number',
'short'
);
/**
* Set this to a writeable folder to enable caching the WSDL in files
*
* @var string
*/
public static $CacheFolder=null;
/**
* Is the cache folder writeable?
*
* @var boolean|NULL
*/
public static $CacheFolderWriteAble=null;
/**
* The cache timeout in seconds (set to zero to disable caching, too)
* If you set the value to -1, the cache will never expire. Then you have
* to use the PhpWsdl->TidyCache method for cleaning up the cache once
* you've made changes to your webservice.
*
* @var int
*/
public static $CacheTime=3600;
/**
* Write even unoptimized and/or documented XML to the cache?
*
* @var boolean
*/
public static $CacheAllWsdl=false;
/**
* Parse documentation?
*
* @var boolean
*/
public $ParseDocs=true;
/**
* Include documentation tags in WSDL, if the optimizer is disabled?
*
* @var boolean
*/
public $IncludeDocs=true;
/**
* Force sending WSDL (has a higher priority than PhpWsdl->ForceNotOutputWsdl)
*
* @var boolean
*/
public $ForceOutputWsdl=false;
/**
* Force NOT sending WSDL (disable sending WSDL, has a higher priority than ?WSDL f.e.)
*
* @var boolean
*/
public $ForceNotOutputWsdl=false;
/**
* Force sending HTML (has a higher priority than PhpWsdl->ForceNotOutputHtml)
*
* @var boolean
*/
public $ForceOutputHtml=false;
/**
* Force NOT sending HTML (disable sending HTML)
*
* @var boolean
*/
public $ForceNotOutputHtml=false;
/**
* The headline for the HTML output or NULL to use the default
*
* @var string
*/
public $HtmlHeadLine=null;
/**
* Force sending PHP (has a higher priority than PhpWsdl->ForceNotOutputPhp)
*
* @var boolean
*/
public $ForceOutputPhp=false;
/**
* Force NOT sending PHP (disable sending PHP)
*
* @var boolean
*/
public $ForceNotOutputPhp=false;
/**
* Regular expression parse a class name
*
* @var string
*/
public static $classRx='/^.*class\s+([^\s]+)\s*\{.*$/is';
/**
* The HTML2PDF license key (see www.htmltopdf.de)
*
* @var string
*/
public static $HTML2PDFLicenseKey=null;
/**
* The URI to the HTML2PDF http API
*
* @var string
*/
public static $HTML2PDFAPI='http://online.htmltopdf.de/';
/**
* The HTML2PDF settings (only available when using a valid license key)
*
* @var array
*/
public static $HTML2PDFSettings=Array();
/**
* Saves if the sources have been parsed
*
* @var boolean
*/
public $SourcesParsed=false;
/**
* Saves if the configuration has already been determined
*
* @var boolean
*/
public $ConfigurationDetermined=false;
/**
* The current PHP SoapServer object
*
* @var SoapServer
*/
public $SoapServer=null;
/**
* Is a http Auth login required to run the SOAP server?
*
* @var boolean
*/
public $RequireLogin=false;
/**
* Debugging messages
*
* @var string[]
*/
public static $DebugInfo=Array();
/**
* En- / Disable the debugging mode
*
* @var boolean
*/
public static $Debugging=false;
/**
* The debug file to write to
*
* @var string
*/
public static $DebugFile=null;
/**
* Put backtrace information in debugging messages
*
* @var boolean
*/
public static $DebugBackTrace=false;
/**
* A debugging handler
*
* @var string|array
*/
public static $DebugHandler=null;
/**
* WSDL namespaces
*
* @var array
*/
public static $NameSpaces=null;
/**
* PhpWsdl constructor
* Note: The quick mode by giving TRUE as first parameter is deprecated and will be removed from version 3.0.
* Use PhpWsdl::RunQuickMode() instead
*
* @param string|boolean $nameSpace Namespace or NULL to let PhpWsdl determine it, or TRUE to run everything by determining all configuration -> quick mode (default: NULL)
* @param string|string[] $endPoint Endpoint URI or NULL to let PhpWsdl determine it - or, in quick mode, the webservice class filename(s) (default: NULL)
* @param string $cacheFolder The folder for caching WSDL or NULL to use the systems default (default: NULL)
* @param string|string[] $file Filename or array of filenames or NULL (default: NULL)
* @param string $name Webservice name or NULL to let PhpWsdl determine it (default: NULL)
* @param PhpWsdlMethod[] $methods Array of methods or NULL (default: NULL)
* @param PhpWsdlComplex[] $types Array of complex types or NULL (default: NULL)
* @param boolean $outputOnRequest Output WSDL on request? (default: FALSE)
* @param boolean|string|object|array $runServer Run SOAP server? (default: FALSE)
*/
public function PhpWsdl(
$nameSpace=null,
$endPoint=null,
$cacheFolder=null,
$file=null,
$name=null,
$methods=null,
$types=null,
$outputOnRequest=false,
$runServer=false
){
// Quick mode
self::Debug('PhpWsdl constructor called');
$quickRun=false;
if($nameSpace===true){
self::Debug('Quick mode detected');
$quickRun=true;
$nameSpace=null;
if(!is_null($endPoint)){
if(self::$Debugging)
self::Debug('Filename(s): '.print_r($endPoint,true));
$endPoint=null;
}
}
// SOAP server options
$this->SoapServerOptions=Array(
'soap_version' => (defined('SOAP_1_2'))?SOAP_1_2:SOAP_1_1,
'encoding' => 'UTF-8',
'compression' => SOAP_COMPRESSION_ACCEPT|SOAP_COMPRESSION_GZIP|9
);
// Optimizer settings
$this->Optimize=!isset($_GET['readable']);// Call with "?WSDL&readable" to get human readable WSDL
self::Debug('Optimizer is '.(($this->Optimize)?'enabled':'disabled'));
// Cache settings
if(!is_null($cacheFolder)){
self::Debug('Cache folder is '.$cacheFolder);
self::$CacheFolder=$cacheFolder;
}
// Namespace
$this->NameSpace=(is_null($nameSpace))?$this->DetermineNameSpace():$nameSpace;
self::Debug('Namespace is '.$this->NameSpace);
// Endpoint
$this->EndPoint=((!is_null($endPoint)))?$endPoint:$this->DetermineEndPoint();
self::Debug('Endpoint is '.$this->EndPoint);
// Name
if(!is_null($name)){
self::Debug('Name is '.$name);
$this->Name=$name;
}
// Source files
if(!is_null($file)){
if(self::$Debugging)
self::Debug('Filename(s): '.print_r($file,true));
$this->Files=array_merge($this->Files,(is_array($file))?$file:Array($file));
}
// Methods
$this->Methods=(!is_null($methods))?$methods:Array();
if(sizeof($this->Methods)>0&&self::$Debugging)
self::Debug('Methods: '.print_r($this->Methods,true));
// Types
$this->Types=(!is_null($types))?$types:Array();
if(sizeof($this->Types)>0&&self::$Debugging)
self::Debug('Types: '.print_r($this->Types,true));
// Constructor hook
self::CallHook(
'ConstructorHook',
Array(
'server' => $this,
'output' => &$outputOnRequest,
'run' => &$runServer,
'quickmode' => &$quickRun
)
);
// WSDL output
if($outputOnRequest&&!$runServer)
$this->OutputWsdlOnRequest();
// Run the server
if($quickRun||$runServer)
$this->RunServer(null,(is_bool($runServer))?null:$runServer);
}
/**
* Create an instance of PhpWsdl
* Note: The quick mode by giving TRUE as first parameter is deprecated and will be removed from version 3.0.
* Use PhpWsdl::RunQuickMode() instead
*
* @param string|boolean $nameSpace Namespace or NULL to let PhpWsdl determine it, or TRUE to run everything by determining all configuration -> quick mode (default: NULL)
* @param string|string[] $endPoint Endpoint URI or NULL to let PhpWsdl determine it - or, in quick mode, the webservice class filename(s) (default: NULL)
* @param string $cacheFolder The folder for caching WSDL or NULL to use the systems default (default: NULL)
* @param string|string[] $file Filename or array of filenames or NULL (default: NULL)
* @param string $name Webservice name or NULL to let PhpWsdl determine it (default: NULL)
* @param PhpWsdlMethod[] $methods Array of methods or NULL (default: NULL)
* @param PhpWsdlComplex[] $types Array of complex types or NULL (default: NULL)
* @param boolean $outputOnRequest Output WSDL on request? (default: FALSE)
* @param boolean|string|object|array $runServer Run SOAP server? (default: FALSE)
* @return PhpWsdl The PhpWsdl object
*/
public static function CreateInstance(
$nameSpace=null,
$endPoint=null,
$cacheFolder=null,
$file=null,
$name=null,
$methods=null,
$types=null,
$outputOnRequest=false,
$runServer=false
){
self::Debug('Create new PhpWsdl instance');
$obj=null;
self::CallHook(
'BeforeCreateInstanceHook',
Array(
'server' => &$obj,
'namespace' => &$nameSpace,
'endpoint' => &$endPoint,
'cachefolder' => &$cacheFolder,
'file' => &$file,
'name' => &$name,
'methods' => &$methods,
'types' => &$types,
'outputonrequest'=> &$outputOnRequest,
'runserver' => &$runServer
)
);
if(is_null($obj))
$obj=new PhpWsdl($nameSpace,$endPoint,$cacheFolder,$file,$name,$methods,$types,$outputOnRequest,$runServer);
self::CallHook(
'CreateInstanceHook',
Array(
'server' => &$obj
)
);
return $obj;
}
/**
* Run the PhpWsdl SOAP server in quick mode
*
* @param string|string[] $file The webservice handler class file or a list of files or NULL (default: NULL)
*/
public static function RunQuickMode($file=null){
self::Debug('Run quick mode');
$server=self::CreateInstance();
if(!is_null($file))
$server->Files=(is_array($file))?$file:Array($file);
$server->RunServer();
}
/**
* Determine if WSDL was requested by the client
*
* @return boolean WSDL requested?
*/
public function IsWsdlRequested(){
return $this->ForceOutputWsdl||((isset($_GET['wsdl'])||isset($_GET['WSDL']))&&!$this->ForceNotOutputWsdl);
}
/**
* Determine if HTML was requested by the client
*
* @return boolean HTML requested?
*/
public function IsHtmlRequested(){
return $this->ForceOutputHtml||(strlen(file_get_contents('php://input'))<1&&!$this->ForceNotOutputHtml);
}
/**
* Determine if PHP was requested by the client
*
* @return boolean PHP requested?
*/
public function IsPhpRequested(){
return $this->ForceOutputPhp||((isset($_GET['phpsoapclient'])||isset($_GET['PHPSOAPCLIENT']))&&!$this->ForceNotOutputPhp);
}
/**
* Determine if this request is a SOAP request
*
* @return boolean
*/
public function IsSoapRequest(){
return !$this->IsHtmlRequested()&&!$this->IsWsdlRequested()&&!$this->IsPhpRequested();
}
/**
* Determine if only global methods are served
*
* @return boolean Only global methods?
*/
public function IsOnlyGlobal(){
$res=true;
$i=-1;
$len=sizeof($this->Methods);
while(++$i<$len)
if(!$this->Methods[$i]->IsGlobal){
$res=false;
break;
}
return $res;
}
/**
* Disble caching
*
* @param bool $allCaching Do not only set the timeout to zero? (default: TRUE)
*/
public static function DisableCache($allCaching=true){
self::Debug('Disable '.(($allCaching)?'all':'this').' caching');
if($allCaching)
self::$CacheFolder=null;
if(!$allCaching)
self::$CacheTime=0;
}
/**
* Enable caching
*
* @param string $folder The cache folder or NULL to use a system temporary directory (default: NULL)
* @param int $timeout The caching timeout in seconds or NULL to use the previous value or the default (3600) (default: NULL)
*/
public static function EnableCache($folder=null,$timeout=null){
if(is_null($folder)&&is_null(self::$CacheFolder)){
if(self::IsCacheFolderWriteAble('./cache')){
$folder='./cache';
}else if(self::IsCacheFolderWriteAble(dirname(__FILE__).'/cache')){
$folder=dirname(__FILE__).'/cache';
}else if(self::IsCacheFolderWriteAble(sys_get_temp_dir())){
$folder=sys_get_temp_dir();
}else{
self::Debug('Could not find a cache folder');
}
}
if(is_null($timeout))
$timeout=(self::$CacheTime!=0)?self::$CacheTime:3600;
self::Debug('Enable cache in folder "'.((is_null($folder))?'(none)':$folder).'" with timeout '.$timeout.' seconds');
self::$CacheFolder=$folder;
self::$CacheTime=$timeout;
}
/**
* Determine the configuration
*
* @return boolean Succeed?
*/
public function DetermineConfiguration(){
if(!is_null($this->GetWsdlFromCache()))
return true;
$this->ParseSource();
$mLen=sizeof($this->Methods);
$tLen=sizeof($this->Types);
$fLen=sizeof($this->Files);
if($this->ConfigurationDetermined)
return ($mLen>0||$tLen>0)&&!is_null($this->Name);
self::Debug('Determine configuration');
$this->ConfigurationDetermined=true;
$tryWebService=
!$this->IsFileInList('class.webservice.php')&&
(
file_exists('class.webservice.php')||
file_exists(dirname(__FILE__).'/class.webservice.php')
);
// No methods or types? Try to parse them from the current script
if($mLen<1&&$tLen<1){
$tryFiles=Array();
if($tryWebService){
if(file_exists('class.webservice.php'))
$tryFiles[]='class.webservice.php';
if(file_exists(dirname(__FILE__).'/class.webservice.php'))
$tryFiles[]=dirname(__FILE__).'/class.webservice.php';
}
if(!$this->IsFileInList($_SERVER['SCRIPT_FILENAME']))
$tryFiles[]=$_SERVER['SCRIPT_FILENAME'];
$i=-1;
$len=sizeof($tryFiles);
while(++$i<$len){
$file=$tryFiles[$i];
self::Debug('Try to load objects from '.$file);
$this->ParseSource(false,file_get_contents($file));
$mLen=sizeof($this->Methods);
$tLen=sizeof($this->Types);
if($mLen<1&&$tLen<1)
continue;
self::Debug('Found objects, adding the file to list');
$this->Files[]=$file;
$fLen++;
break;
}
if($mLen<1&&$tLen<1)
return false;
}
// No class name? Try to parse one from the current files
if(!is_null($this->Name))
return true;
$tryFiles=Array();
if(!$this->IsFileInList($_SERVER['SCRIPT_FILENAME']))
$tryFiles[]=$_SERVER['SCRIPT_FILENAME'];
if($tryWebService){
if(file_exists('class.webservice.php'))
$tryFiles[]='class.webservice.php';
if(file_exists(dirname(__FILE__).'/class.webservice.php'))
$tryFiles[]=dirname(__FILE__).'/class.webservice.php';
}
$tryFiles=array_merge($this->Files,$tryFiles);
$i=-1;
$len=sizeof($tryFiles);
$class=null;
while(++$i<$len){
$file=$tryFiles[$i];
self::Debug('Try to determine the class name from '.$file);
$temp=file_get_contents($file);
if(!preg_match(self::$classRx,$temp))
continue;
$class=preg_replace(self::$classRx,"$1",$temp);
self::Debug('Found class name '.$class);
break;
}
// No class name yet? Use the default if only global methods are present
if(is_null($class)&&$this->IsOnlyGlobal()){
self::Debug('Using default webservice name');
$class='SoapWebService';
}
$this->Name=$class;
return !is_null($class);
}
/**
* Determine the endpoint URI
*/
public function DetermineEndPoint(){
$ssl=isset($_SERVER['HTTPS'])&&$_SERVER['HTTPS']=='on';
$res='http'.(($ssl)?'s':'').'://'.$_SERVER['SERVER_NAME'];
if(((!$ssl&&$_SERVER['SERVER_PORT']!=80)||($ssl&&$_SERVER['SERVER_PORT']!=443)))
$res.=':'.$_SERVER['SERVER_PORT'];// Append the non-default server port
return $res.$_SERVER['SCRIPT_NAME'];
}
/**
* Determine the namespace
*/
public function DetermineNameSpace(){
return 'http://'.$_SERVER['SERVER_NAME'].str_replace(basename($_SERVER['SCRIPT_NAME']),'',$_SERVER['SCRIPT_NAME']);
}
/**
* Determine if a file is included in the list of files
*
* @param string $file The filename
* @return boolean In the list?
*/
public function IsFileInList($file){
$file=preg_quote(basename($file));
$i=-1;
$fLen=sizeof($this->Files);
while(++$i<$fLen)
if(preg_match('/^(.*\/)?'.$file.'$/i',$this->Files[$i]))
return true;
return false;
}
/**
* Determine if a type is used as exception type for a method
*
* @param string|PhpWsdlComplex $type A type name or object instance
* @return boolean Used as exception type?
*/
public function IsException($type){
if(is_object($type))
$type=$type->Name;
if(PhpWsdlMethod::$DefaultException==$type)
return true;
$i=-1;
$len=sizeof($this->Methods);
while(++$i<$len)
if($this->Methods[$i]->Exception==$type)
return true;
return false;
}
/**
* Create the WSDL
*
* @param boolean $reCreate Don't use the cached WSDL? (default: FALSE)
* @param boolean $optimize If TRUE, override the PhpWsdl->Optimizer property and force optimizing (default: FALSE)
* @return string The UTF-8 encoded WSDL as string
*/
public function CreateWsdl($reCreate=false,$optimizer=false){
self::Debug('Create WSDL');
// Ask the cache
if(!$reCreate&&(self::$CacheAllWsdl||!$this->IncludeDocs||$optimizer||$this->Optimize)){
self::Debug('Try to get WSDL from the cache');
$wsdl=$this->GetWsdlFromCache();
if(!is_null($wsdl)){
self::Debug('Using cached WSDL');
return (!$optimizer&&!$this->Optimize)?self::FormatXml($wsdl):$wsdl;
}
}
// Prepare the WSDL generator
if(!$this->DetermineConfiguration()){
$mLen=sizeof($this->Methods);
$tLen=sizeof($this->Types);
if($mLen<1&&$tLen<1){
self::Debug('No methods and types');
throw(new Exception('No methods and no complex types are available'));
}
if(is_null($this->Name)){
self::Debug('No name');
throw(new Exception('Could not determine webservice handler class name'));
}
}
$res=Array();
// Create the XML Header
self::CallHook(
'CreateWsdlHeaderHook',
Array(
'server' => $this,
'res' => &$res,
'optimizer' => &$optimizer
)
);
// Create types
self::CallHook(
'CreateWsdlTypeSchemaHook',
Array(
'server' => $this,
'res' => &$res,
'optimizer' => &$optimizer
)
);
// Create messages
self::CallHook(
'CreateWsdlMessagesHook',
Array(
'server' => $this,
'res' => &$res,
'optimizer' => &$optimizer
)
);
// Create port types
self::CallHook(
'CreateWsdlPortsHook',
Array(
'server' => $this,
'res' => &$res,
'optimizer' => &$optimizer
)
);
// Create bindings
self::CallHook(
'CreateWsdlBindingsHook',
Array(
'server' => $this,
'res' => &$res,
'optimizer' => &$optimizer
)
);
// Create the service
self::CallHook(
'CreateWsdlServiceHook',
Array(
'server' => $this,
'res' => &$res,
'optimizer' => &$optimizer
)
);
// Finish the WSDL XML string
self::CallHook(
'CreateWsdlFooterHook',
Array(
'server' => $this,
'res' => &$res,
'optimizer' => &$optimizer
)
);
// Run the optimizer
self::CallHook(
'CreateWsdlOptimizeHook',
Array(
'server' => $this,
'res' => &$res,
'optimizer' => &$optimizer
)
);
// Fill the cache
if(self::$CacheAllWsdl||!$this->IncludeDocs||$optimizer||$this->Optimize){
self::Debug('Cache created WSDL');
$this->WriteWsdlToCache(
(
!self::$CacheAllWsdl&&
!$optimizer&&
!$this->Optimize
)
?self::OptimizeXml($res)
:$res
,
null,
null,
true
);
}
return $this->WSDL;
}
/**
* Create header
*
* @param array $data Data array
* @return boolean Response
*/
public static function CreateWsdlHeader($data){
self::Debug('CreateWsdlHeader');
$res=&$data['res'];
$server=$data['server'];
$res[]='<?xml version="1.0" encoding="UTF-8"?>';
$temp=Array();
$keys=array_keys(self::$NameSpaces);
$i=-1;
$len=sizeof($keys);
while(++$i<$len)
$temp[]='xmlns:'.$keys[$i].'="'.self::$NameSpaces[$keys[$i]].'"';
$res[]='<wsdl:definitions xmlns:tns="'.$server->NameSpace.'" targetNamespace="'.$server->NameSpace.'" '.implode(' ',$temp).'>';
return true;
}
/**
* Create type schema
*
* @param array $data Data array
* @return boolean Response
*/
public static function CreateWsdlTypeSchema($data){
self::Debug('CreateWsdlTypeSchema');
$res=&$data['res'];
$server=$data['server'];
$tLen=sizeof($server->Types);
if($tLen>0){
$res[]='<wsdl:types>';
$res[]='<s:schema targetNamespace="'.$server->NameSpace.'">';
$i=-1;
while(++$i<$tLen)
$res[]=$server->Types[$i]->CreateType($server);
self::CallHook(
'CreateWsdlTypesHook',
$data
);
$res[]='</s:schema>';
$res[]='</wsdl:types>';
}
return true;
}
/**
* Create messages
*