1
|
|
|
<?php |
|
|
|
|
2
|
|
|
use WSDL\DocumentLiteralWrapper; |
3
|
|
|
use WSDL\WSDLCreator; |
4
|
|
|
use WSDL\XML\Styles\DocumentLiteralWrapped; |
5
|
|
|
|
6
|
|
|
require_once '../../vendor/autoload.php'; |
7
|
|
|
|
8
|
|
|
$wsdl = new WSDLCreator('ObjectSoapServer', 'http://localhost/wsdl-creator/examples/document_literal_wrapped/ObjectExampleSoapServer.php'); |
9
|
|
|
$wsdl->setNamespace("http://foo.bar/")->setBindingStyle(new DocumentLiteralWrapped()); |
10
|
|
|
|
11
|
|
|
if (isset($_GET['wsdl'])) { |
12
|
|
|
$wsdl->renderWSDL(); |
13
|
|
|
exit; |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
$wsdl->renderWSDLService(); |
17
|
|
|
|
18
|
|
|
$server = new SoapServer('http://localhost/wsdl-creator/examples/document_literal_wrapped/ObjectExampleSoapServer.php?wsdl', array( |
19
|
|
|
'uri' => $wsdl->getNamespaceWithSanitizedClass(), |
20
|
|
|
'location' => $wsdl->getLocation(), |
21
|
|
|
'style' => SOAP_DOCUMENT, |
22
|
|
|
'use' => SOAP_LITERAL |
23
|
|
|
)); |
24
|
|
|
$server->setObject(new DocumentLiteralWrapper(new ObjectSoapServer())); |
25
|
|
|
$server->handle(); |
26
|
|
|
|
27
|
|
|
class Agent |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @type string |
31
|
|
|
*/ |
32
|
|
|
public $name; |
33
|
|
|
/** |
34
|
|
|
* @type int |
35
|
|
|
*/ |
36
|
|
|
public $number; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
View Code Duplication |
class ObjectSoapServer |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
/** |
42
|
|
|
* @WebMethod |
43
|
|
|
* @param object $info @string=$name @int=$age |
44
|
|
|
* @return string $returnInfo |
45
|
|
|
*/ |
46
|
|
|
public function userInfo($info) |
47
|
|
|
{ |
48
|
|
|
return 'Your name is: ' . $info->name . ' and you have ' . $info->age . ' years old, it\'s ok?'; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @WebMethod |
53
|
|
|
* @param string $name |
54
|
|
|
* @param string $number |
55
|
|
|
* @return object $agentNameWithId @(wrapper $agent @className=Agent) @int=$id |
56
|
|
|
*/ |
57
|
|
|
public function getAgentWithId($name, $number) |
58
|
|
|
{ |
59
|
|
|
$agent = new Agent(); |
60
|
|
|
$agent->name = $name; |
61
|
|
|
$agent->number = $number; |
|
|
|
|
62
|
|
|
|
63
|
|
|
$return = new stdClass(); |
64
|
|
|
$return->agent = $agent; |
65
|
|
|
$return->id = 3543456; |
66
|
|
|
return $return; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @WebMethod |
71
|
|
|
* @param object $namesInfo @string[]=$names @int=$id |
72
|
|
|
* @return string $namesForId |
73
|
|
|
*/ |
74
|
|
|
public function namesForId($namesInfo) |
75
|
|
|
{ |
76
|
|
|
//FIXME incorrect $names array |
77
|
|
|
return '[#' . $namesInfo->id . '] Names: ' . implode(', ', $namesInfo->names); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @WebMethod |
82
|
|
|
* @return object[] $companies @string=$name @int=$id |
83
|
|
|
*/ |
84
|
|
|
public function getCompanies() |
85
|
|
|
{ |
86
|
|
|
//FIXME incorrect response structure |
87
|
|
|
$companies = array(); |
88
|
|
|
$companies[0] = new stdClass(); |
89
|
|
|
$companies[0]->name = 'Example1'; |
90
|
|
|
$companies[0]->id = '1'; |
91
|
|
|
$companies[1] = new stdClass(); |
92
|
|
|
$companies[1]->name = 'Example2'; |
93
|
|
|
$companies[1]->id = '3'; |
94
|
|
|
return $companies; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @WebMethod |
99
|
|
|
* @return object $listOfAgents @(wrapper[] $agents @className=Agent) @int=$id |
100
|
|
|
*/ |
101
|
|
|
public function getListOfAgentsWithId() |
102
|
|
|
{ |
103
|
|
|
//FIXME incorrect response structure |
104
|
|
|
$obj = new stdClass(); |
105
|
|
|
$obj->agents[0] = new Agent(); |
106
|
|
|
$obj->agents[0]->name = 'agent1'; |
107
|
|
|
$obj->agents[1] = new Agent(); |
108
|
|
|
$obj->agents[1]->name = 'agent2'; |
109
|
|
|
$obj->id = '555'; |
110
|
|
|
return $obj; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @WebMethod |
115
|
|
|
* @param object[] $payments @float[]=$payment @string=$user |
116
|
|
|
* @return object[] $paymentsUsers @string=$user @int=$countPayment |
117
|
|
|
*/ |
118
|
|
|
public function setPayment($payments) |
119
|
|
|
{ |
120
|
|
|
//FIXME incorrect response structure |
121
|
|
|
$paymentsUsers = array(); |
122
|
|
|
foreach ($payments as $i => $payment) { |
123
|
|
|
$paymentsUsers[$i] = new stdClass(); |
124
|
|
|
$paymentsUsers[$i]->user = $payment->user; |
125
|
|
|
$paymentsUsers[$i]->countPayment = count($payment->payment); |
126
|
|
|
} |
127
|
|
|
return $paymentsUsers; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @WebMethod |
132
|
|
|
* @return object[] $agentsWithPayment @(wrapper $agent @className=Agent) @float=$payment |
133
|
|
|
*/ |
134
|
|
|
public function getAgentsWithPayment() |
135
|
|
|
{ |
136
|
|
|
//FIXME incorrect response structure |
137
|
|
|
$obj = array(); |
138
|
|
|
$obj[0] = new stdClass(); |
139
|
|
|
$obj[0]->agent = new Agent(); |
140
|
|
|
$obj[0]->agent->name = 'agent1'; |
141
|
|
|
$obj[0]->payment = '123.56'; |
142
|
|
|
$obj[1] = new stdClass(); |
143
|
|
|
$obj[1]->agent = new Agent(); |
144
|
|
|
$obj[1]->agent->name = 'agent2'; |
145
|
|
|
$obj[1]->payment = '6546.56'; |
146
|
|
|
return $obj; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @WebMethod |
151
|
|
|
* @return object[] $employeesList @(wrapper[] $agents @className=Agent) |
152
|
|
|
*/ |
153
|
|
|
public function getEmployeesWithAgents() |
154
|
|
|
{ |
155
|
|
|
//FIXME incorrect response structure |
156
|
|
|
$obj = array(); |
157
|
|
|
$obj[0] = new stdClass(); |
158
|
|
|
$obj[0]->agents[0] = new Agent(); |
159
|
|
|
$obj[0]->agents[0]->name = 'agent1'; |
160
|
|
|
$obj[0]->agents[1] = new Agent(); |
161
|
|
|
$obj[0]->agents[1]->name = 'agent2'; |
162
|
|
|
$obj[1] = new stdClass(); |
163
|
|
|
$obj[1]->agents[0] = new Agent(); |
164
|
|
|
$obj[1]->agents[0]->name = 'agent3'; |
165
|
|
|
$obj[1]->agents[1] = new Agent(); |
166
|
|
|
$obj[1]->agents[1]->name = 'agent4'; |
167
|
|
|
return $obj; |
168
|
|
|
} |
169
|
|
|
} |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.