|
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('WrapperSoapServer', 'http://localhost/wsdl-creator/examples/document_literal_wrapped/WrapperExampleSoapServer.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/WrapperExampleSoapServer.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 WrapperSoapServer())); |
|
25
|
|
|
$server->handle(); |
|
26
|
|
|
|
|
27
|
|
|
class User |
|
|
|
|
|
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* @type string |
|
31
|
|
|
*/ |
|
32
|
|
|
public $name; |
|
33
|
|
|
/** |
|
34
|
|
|
* @type int |
|
35
|
|
|
*/ |
|
36
|
|
|
public $age; |
|
37
|
|
|
/** |
|
38
|
|
|
* @type double |
|
39
|
|
|
*/ |
|
40
|
|
|
public $payment; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
class Employee |
|
|
|
|
|
|
44
|
|
|
{ |
|
45
|
|
|
/** |
|
46
|
|
|
* @type int |
|
47
|
|
|
*/ |
|
48
|
|
|
public $id; |
|
49
|
|
|
/** |
|
50
|
|
|
* @type string |
|
51
|
|
|
*/ |
|
52
|
|
|
public $department; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
View Code Duplication |
class WrapperSoapServer |
|
|
|
|
|
|
56
|
|
|
{ |
|
57
|
|
|
/** |
|
58
|
|
|
* @WebMethod |
|
59
|
|
|
* @param wrapper $user @className=User |
|
60
|
|
|
* @param int $id |
|
61
|
|
|
* @return string $nameWithAge |
|
62
|
|
|
*/ |
|
63
|
|
|
public function getUserString($user, $id) |
|
64
|
|
|
{ |
|
65
|
|
|
return '[#' . $id . ']Your name is: ' . $user->name . ' and you have ' . $user->age . ' years old with payment ' . $user->payment; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @WebMethod |
|
70
|
|
|
* @param string $name |
|
71
|
|
|
* @param string $age |
|
72
|
|
|
* @param string $payment |
|
73
|
|
|
* @return wrapper $userReturn @className=User |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getUser($name, $age, $payment) |
|
76
|
|
|
{ |
|
77
|
|
|
//FIXME incorrect response structure |
|
78
|
|
|
$user = new User(); |
|
79
|
|
|
$user->name = $name; |
|
80
|
|
|
$user->age = $age; |
|
|
|
|
|
|
81
|
|
|
$user->payment = $payment; |
|
|
|
|
|
|
82
|
|
|
return $user; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @WebMethod |
|
87
|
|
|
* @return wrapper[] $employees @className=Employee |
|
88
|
|
|
*/ |
|
89
|
|
|
public function getEmployees() |
|
90
|
|
|
{ |
|
91
|
|
|
//FIXME incorrect response structure |
|
92
|
|
|
$employees = array(); |
|
93
|
|
|
$departments = array('IT', 'Logistics', 'Management'); |
|
94
|
|
|
for ($i = 0; $i < 3; $i++) { |
|
95
|
|
|
$employee = new Employee(); |
|
96
|
|
|
$employee->id = 2 + $i + 1; |
|
97
|
|
|
$employee->department = $departments[$i]; |
|
98
|
|
|
$employees[] = $employee; |
|
99
|
|
|
} |
|
100
|
|
|
return $employees; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @WebMethod |
|
105
|
|
|
* @param wrapper[] $employeesList @className=Employee |
|
106
|
|
|
* @return string $str |
|
107
|
|
|
*/ |
|
108
|
|
|
public function getEmployeesDepartments($employeesList) |
|
109
|
|
|
{ |
|
110
|
|
|
//FIXME incorrect response structure |
|
111
|
|
|
$names = array(); |
|
112
|
|
|
foreach ($employeesList as $employee) { |
|
113
|
|
|
$names[] = $employee->department; |
|
114
|
|
|
} |
|
115
|
|
|
return implode(', ', $names); |
|
116
|
|
|
} |
|
117
|
|
|
} |
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.