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
|
|
|
ini_set("soap.wsdl_cache_enabled", 0); |
9
|
|
|
|
10
|
|
|
$wsdl = new WSDLCreator('SimpleSoapServer', 'http://localhost/wsdl-creator/examples/document_literal_wrapped/SimpleExampleSoapServer.php'); |
11
|
|
|
$wsdl->setNamespace("http://foo.bar/")->setBindingStyle(new DocumentLiteralWrapped()); |
12
|
|
|
|
13
|
|
|
if (isset($_GET['wsdl'])) { |
14
|
|
|
$wsdl->renderWSDL(); |
15
|
|
|
exit; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
$wsdl->renderWSDLService(); |
19
|
|
|
|
20
|
|
|
$server = new SoapServer('http://localhost/wsdl-creator/examples/document_literal_wrapped/SimpleExampleSoapServer.php?wsdl', array( |
21
|
|
|
'uri' => $wsdl->getNamespaceWithSanitizedClass(), |
22
|
|
|
'location' => $wsdl->getLocation(), |
23
|
|
|
'style' => SOAP_DOCUMENT, |
24
|
|
|
'use' => SOAP_LITERAL, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS |
25
|
|
|
)); |
26
|
|
|
$server->setObject(new DocumentLiteralWrapper(new SimpleSoapServer())); |
27
|
|
|
$server->handle(); |
28
|
|
|
|
29
|
|
View Code Duplication |
class SimpleSoapServer |
|
|
|
|
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* @WebMethod |
33
|
|
|
* @param string $name |
34
|
|
|
* @param int $age |
35
|
|
|
* @return string $nameWithAge |
36
|
|
|
*/ |
37
|
|
|
public function getNameWithAge($name, $age) |
38
|
|
|
{ |
39
|
|
|
return 'Your name is: ' . $name . ' and you have ' . $age . ' years old'; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @WebMethod |
44
|
|
|
* @param string[] $names |
45
|
|
|
* @return string $userNames |
46
|
|
|
*/ |
47
|
|
|
public function getNameForUsers($names) |
48
|
|
|
{ |
49
|
|
|
//FIXME correct array of $names |
50
|
|
|
return 'User names: ' . implode(', ', $names); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @WebMethod |
55
|
|
|
* @param int $max |
56
|
|
|
* @return string[] $count |
57
|
|
|
*/ |
58
|
|
|
public function countTo($max) |
59
|
|
|
{ |
60
|
|
|
//FIXME incorrect structure of response |
61
|
|
|
$array = array(); |
62
|
|
|
for ($i = 0; $i < $max; $i++) { |
63
|
|
|
$array[] = 'Number: ' . ($i + 1); |
64
|
|
|
} |
65
|
|
|
return $array; |
66
|
|
|
} |
67
|
|
|
} |
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.