forked from jk/php-wsdl-creator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.phpwsdl.php
2926 lines (2847 loc) · 99.1 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 Muller-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');
if (!class_exists('PhpWsdlServers'))
require_once(dirname(__FILE__) . '/servers/class.phpwsdl.servers.php');
if (!class_exists('PhpWsdlJavaScriptPacker'))
require_once(dirname(__FILE__) . '/servers/class.phpwsdl.servers-jspacker.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;
/**
* 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;
/**
* 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 = 'https://online.htmltopdf.de/';
/**
* The HTML2PDF settings (only available when using a valid license key)
*
* @var array
*/
public static $HTML2PDFSettings = array();
/**
* 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;
/**
* 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;
/**
* 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;
/**
* 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;
/**
* 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)
* @throws Exception
*/
public function __construct(
$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);
}
/**
* Add a debugging message
*
* @param string $str The message to add to the debug protocol
*/
public static function Debug($str)
{
if (!self::$Debugging)
return;
if (!is_null(self::$DebugHandler)) {
call_user_func(self::$DebugHandler, $str);
return;
}
$temp = date('Y-m-d H:i:s') . "\t" . $str;
if (self::$DebugBackTrace) {
$trace = debug_backtrace();
$temp .= " ('" . $trace[1]['function'] . "' in '" . basename($trace[1]['file']) . "' at line #" . $trace[1]['line'] . ")";
}
self::$DebugInfo[] = $temp;
if (!is_null(self::$DebugFile))
if (file_put_contents(self::$DebugFile, $temp . "\n", FILE_APPEND) === false) {
$temp = self::$DebugFile;
self::$DebugFile = null;
self::Debug('Could not write to debug file "' . $temp . '"');
}
}
/**
* Determine the namespace
*/
public function DetermineNameSpace()
{
return 'https://' . $_SERVER['SERVER_NAME'] . str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
}
/**
* 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'];
}
/**
* Call a hook function
*
* @param string $name The hook name
* @param mixed $data The parameter (default: NULL)
* @return boolean Response
*/
public static function CallHook($name, $data = null)
{
self::Debug('Call hook ' . $name);
if (!self::HasHookHandler($name))
return true;
$keys = array_keys(self::$Config['extensions'][$name]);
$i = -1;
$len = sizeof($keys);
while (++$i < $len) {
$fnc = self::$Config['extensions'][$name][$keys[$i]];
self::Debug('Call ' . (is_array($fnc) ? print_r($fnc, true) : $fnc));
if (is_string($fnc) && strpos($fnc, '::') > -1) $fnc = explode('::', $fnc);
if (!call_user_func($fnc, $data)) {
self::Debug('Handler stopped hook execution');
return false;
}
}
return true;
}
/**
* Determine if a hook has a registered handler
*
* @param string $hook The hook name
* @return boolean Has handler?
*/
public static function HasHookHandler($hook)
{
return isset(self::$Config['extensions'][$hook]);
}
/**
* Output the WSDL to the client, if requested
*
* @param boolean $andExit Exit after sending WSDL? (default: TRUE)
* @return boolean Has the WSDL been sent to the client?
*/
public function OutputWsdlOnRequest($andExit = true)
{
if (!$this->IsWsdlRequested())
return false;
$this->OutputWsdl();
if ($andExit) {
self::Debug('Exit script execution');
exit;
}
return true;
}
/**
* 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);
}
/**
* Output the WSDL to the client
*
* @param boolean $withHeaders Output XML headers? (default: TRUE)
* @throws Exception
*/
public function OutputWsdl($withHeaders = true)
{
if (!self::CallHook(
'OutputWsdlHook',
array(
'server' => $this
)
)
)
return;
self::Debug('Output WSDL');
if ($withHeaders)
header('Content-Type: text/xml; charset=UTF-8');
echo $this->CreateWsdl();
}
/**
* 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
* @throws Exception
*/
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;
}
/**
* Get the WSDL from the cache
*
* @param string $file The WSDL cache filename or NULL to use the default (default: NULL)
* @param boolean $force Force this even if the cache is timed out? (default: FALSE)
* @param boolean $nounserialize Don't unserialize the PhpWsdl* objects? (default: FALSE)
* @return string The cached WSDL
*/
public function GetWsdlFromCache($file = null, $force = false, $nounserialize = false)
{
self::Debug('Get WSDL from cache');
if (!is_null($this->WSDL))
return $this->WSDL;
if (is_null($file))
$file = $this->GetCacheFileName();
if (!$force) {
if (!$this->IsCacheValid($file))
return null;
} else if (!$this->CacheFileExists($file)) {
return null;
}
$this->WSDL = file_get_contents($file);
if (!$nounserialize) {
self::Debug('Unserialize methods, types and files');
$data = unserialize(file_get_contents($file . '.obj'));
$this->Methods = $data['methods'];
$this->Types = $data['types'];
$this->Files = $data['files'];
$this->Name = $data['name'];
$this->Docs = $data['docs'];
$this->HTML = $data['html'];
$this->PHP = $data['php'];
$this->WsdlUri = $data['wsdluri'];
$this->PhpUri = $data['phpuri'];
$this->DocUri = $data['docuri'];
$this->HandlerPhp = $data['handler'];
self::CallHook(
'ReadCacheHook',
array(
'server' => $this,
'data' => &$data
)
);
if ($data['version'] != self::$VERSION) {
self::Debug('Could not use cache from version ' . $data['version']);
$this->Methods = array();
$this->Types = array();
$this->Files = array();
$this->Name = null;
$this->Docs = null;
$this->HTML = null;
$this->PHP = null;
$this->WsdlUri = null;
$this->PhpUri = null;
$this->DocUri = null;
$this->WSDL = null;
$this->TidyCacheFolder(true);
return null;
}
}
$this->ConfigurationDetermined = true;
$this->SourcesParsed = true;
return $this->WSDL;
}
/**
* Get the cache filename
*
* @param string $endpoint The endpoint URI or NULL to use the PhpWsdl->EndPoint property (default: NULL)
* @return string The cache filename or NULL, if caching is disabled
*/
public function GetCacheFileName($endpoint = null)
{
$data = array(
'server' => $this,
'endpoint' => $endpoint,
'filename' => (is_null(self::$CacheFolder)) ? null : self::$CacheFolder . '/' . sha1((is_null($endpoint)) ? $this->EndPoint : $endpoint) . '.wsdl'
);
self::CallHook(
'CacheFileNameHook',
$data
);
return $data['filename'];
}
/**
* Determine if the existing cache files are still valid
*
* @param string $file The WSDL cache filename or NULL to use the default (default: NULL)
* @return boolean Valid?
*/
public function IsCacheValid($file = null)
{
self::Debug('Check cache valid');
if (is_null($file))
$file = $this->GetCacheFileName();
if (!$this->CacheFileExists($file))
return false;
return self::$CacheTime < 0 || time() - file_get_contents($file . '.cache') <= self::$CacheTime;
}
/**
* Determine if the cache file exists
*
* @param string $file The WSDL cache filename or NULL to use the default (default: NULL)
* @return boolean Are the cache files present?
*/
public function CacheFileExists($file = null)
{
if (is_null($file))
$file = $this->GetCacheFileName();
self::Debug('Check cache file exists ' . $file);
return file_exists($file) && file_exists($file . '.cache');
}
/**
* Delete cache files from the cache folder
*
* @param boolean $mineOnly Only delete the cache files for this definition? (default: FALSE)
* @param boolean $cleanUp Only delete the cache files that are timed out? (default: FALSE)
* @param string $wsdlFile The WSDL filename (default: NULL)
* @return string[] The deleted filenames
*/
public function TidyCacheFolder($mineOnly = false, $cleanUp = false, $wsdlFile = null)
{
if (is_null(self::$CacheFolder))
return array();
$deleted = array();
if ($cleanUp) {
self::Debug('Cleanup cache');
} else if ($mineOnly) {
self::Debug('Clean own cache');
} else {
self::Debug('Clean all cache');
}
if ($mineOnly) {
self::Debug('Delete own cache');
$file = (is_null($wsdlFile)) ? $this->GetCacheFileName() : $wsdlFile;
if ($cleanUp)
if ($this->IsCacheValid($file))
return $deleted;
if (file_exists($file))
if (unlink($file))
$deleted[] = $file;
if (file_exists($file . '.cache'))
if (unlink($file . '.cache'))
$deleted[] = $file . '.cache';
if (file_exists($file . '.obj'))
if (unlink($file . '.obj'))
$deleted[] = $file . '.obj';
self::Debug(sizeof($deleted) . ' files deleted');
} else {
self::Debug('Delete whole cache');
$files = glob(self::$CacheFolder . (($cleanUp) ? '/*.wsdl' : '/*.wsd*'));
if ($files !== false) {
$toDelete = array();
$i = -1;
$len = sizeof($files);
while (++$i < $len) {
$file = $files[$i];
if ($cleanUp) {
if (!$this->IsCacheValid($file))
continue;
$toDelete[] = $file;
$toDelete[] = $file . '.cache';
$toDelete[] = $file . '.obj';
} else {
if (!preg_match('/\.wsdl(\.cache|\.obj)?$/', $file))
continue;
if (unlink($files[$i]))
$deleted[] = $files[$i];
}
}
if ($cleanUp) {
$i = -1;
$len = sizeof($toDelete);
while (++$i < $len)
if (file_exists($toDelete[$i]))
if (unlink($toDelete[$i]))
$deleted[] = $toDelete[$i];
}
self::Debug(sizeof($deleted) . ' files deleted');
} else {
self::Debug('"glob" failed');
}
}
return $deleted;
}
/**
* Format XML human readable
*
* @param string $xml The XML
* @return string Human readable XML
* @throws Exception
*/
public static function FormatXml($xml)
{
self::Debug('Produce human readable XML');
$input = fopen('data://text/plain,' . $xml, 'r');
$output = fopen('php://temp', 'w');
$xf = new PhpWsdlFormatter($input, $output);
$xf->format();
rewind($output);
$xml = stream_get_contents($output);