1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Soap server class which auto-generates a WSDL |
4
|
|
|
* file to initialize PHPs integrated {@link SoapServer} class. |
5
|
|
|
* |
6
|
|
|
* See {@link SOAPModelAccess} for an auto-generated SOAP API for your models. |
7
|
|
|
* |
8
|
|
|
* @todo Improve documentation |
9
|
|
|
*/ |
10
|
|
|
class SapphireSoapServer extends Controller |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var array Map of method name to arguments. |
14
|
|
|
*/ |
15
|
|
|
private static $methods = array(); |
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var array |
19
|
|
|
*/ |
20
|
|
|
private static $xsd_types = array( |
21
|
|
|
'int' => 'xsd:int', |
22
|
|
|
'boolean' => 'xsd:boolean', |
23
|
|
|
'string' => 'xsd:string', |
24
|
|
|
'binary' => 'xsd:base64Binary', |
25
|
|
|
); |
26
|
|
|
|
27
|
|
|
private static $allowed_actions = array( |
|
|
|
|
28
|
|
|
'index', |
29
|
|
|
'wsdl', |
30
|
|
|
); |
31
|
|
|
|
32
|
|
|
public function wsdl() |
33
|
|
|
{ |
34
|
|
|
$this->getResponse()->addHeader('Content-Type', 'text/xml; charset=utf-8'); |
35
|
|
|
|
36
|
|
|
return $this->renderWith('SapphireSoapServer_wsdl'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return string |
41
|
|
|
*/ |
42
|
|
|
public function getWSDLURL() |
43
|
|
|
{ |
44
|
|
|
return Director::absoluteBaseURLWithAuth().$this->Link().'wsdl'; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @return SS_List Collection of ArrayData elements describing |
49
|
|
|
* the method (keys: 'Name', 'Arguments', 'ReturnType') |
50
|
|
|
*/ |
51
|
|
|
public function Methods() |
52
|
|
|
{ |
53
|
|
|
$methods = array(); |
54
|
|
|
|
55
|
|
|
foreach ($this->stat('methods') as $methodName => $arguments) { |
56
|
|
|
$returnType = $arguments['_returns']; |
57
|
|
|
unset($arguments['_returns']); |
58
|
|
|
|
59
|
|
|
$processedArguments = array(); |
60
|
|
|
foreach ($arguments as $argument => $type) { |
61
|
|
|
$processedArguments[] = new ArrayData(array( |
62
|
|
|
'Name' => $argument, |
63
|
|
|
'Type' => self::$xsd_types[$type], |
64
|
|
|
)); |
65
|
|
|
} |
66
|
|
|
$methods[] = new ArrayData(array( |
67
|
|
|
'Name' => $methodName, |
68
|
|
|
'Arguments' => new ArrayList($processedArguments), |
69
|
|
|
'ReturnType' => self::$xsd_types[$returnType], |
70
|
|
|
)); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return new ArrayList($methods); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return string |
78
|
|
|
*/ |
79
|
|
|
public function TargetNamespace() |
80
|
|
|
{ |
81
|
|
|
return Director::absoluteBaseURL(); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return string |
86
|
|
|
*/ |
87
|
|
|
public function ServiceURL() |
88
|
|
|
{ |
89
|
|
|
return Director::absoluteBaseURLWithAuth().$this->class.'/'; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function index() |
93
|
|
|
{ |
94
|
|
|
$wsdl = $this->getViewer('wsdl')->process($this); |
95
|
|
|
$wsdlFile = TEMP_FOLDER.'/sapphire-wsdl-'.$this->class; |
96
|
|
|
$fh = fopen($wsdlFile, 'w'); |
97
|
|
|
fwrite($fh, $wsdl); |
98
|
|
|
fclose($fh); |
99
|
|
|
|
100
|
|
|
$this->getResponse()->addHeader('Content-Type', 'text/xml; charset=utf-8'); |
101
|
|
|
|
102
|
|
|
$s = new SoapServer($wsdlFile, array('cache_wsdl' => WSDL_CACHE_NONE)); |
103
|
|
|
$s->setClass($this->class); |
104
|
|
|
$s->handle(); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.