1
|
|
|
<?php |
2
|
|
|
namespace Clients\DocumentLiteralWrapped; |
3
|
|
|
|
4
|
|
|
use Clients\InitCommand; |
5
|
|
|
use SoapClient; |
6
|
|
|
use stdClass; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
|
10
|
|
|
class WrapperCommand extends InitCommand |
11
|
|
|
{ |
12
|
|
|
protected function configure() |
13
|
|
|
{ |
14
|
|
|
$this->setName('document_literal:wrapper'); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
18
|
|
|
{ |
19
|
|
|
$this->output = $output; |
20
|
|
|
|
21
|
|
|
$this->soapClient = new SoapClient('http://localhost/wsdl-creator/examples/document_literal_wrapped/WrapperExampleSoapServer.php?wsdl', array( |
22
|
|
|
'uri' => "http://foo.bar/", 'location' => 'http://localhost/wsdl-creator/examples/document_literal_wrapped/WrapperExampleSoapServer.php', |
23
|
|
|
'trace' => true, 'cache_wsdl' => WSDL_CACHE_NONE |
24
|
|
|
)); |
25
|
|
|
|
26
|
|
|
$this->serviceInfo('Wrapper Object - document/literal wrapped'); |
27
|
|
|
|
28
|
|
|
$this->renderMethodsTable(); |
29
|
|
|
|
30
|
|
|
$user = new stdClass(); |
31
|
|
|
$user->name = 'john'; |
32
|
|
|
$user->age = 31; |
33
|
|
|
$user->payment = 123.40; |
34
|
|
|
$response = $this->soapClient->getUserString(array('user' => $user, 'id' => 333)); |
35
|
|
|
$this->method('getUserString', array(array('user' => $user, 'id' => 333)), $response); |
36
|
|
|
|
37
|
|
|
$params = new stdClass(); |
38
|
|
|
$params->name = 'peter'; |
39
|
|
|
$params->age = 22; |
40
|
|
|
$params->payment = 32.02; |
41
|
|
|
$response = $this->soapClient->getUser($params); |
42
|
|
|
$this->method('getUser', array($params), $response); |
43
|
|
|
|
44
|
|
|
$response = $this->soapClient->getEmployees(); |
45
|
|
|
$this->method('getEmployees', array(), $response); |
46
|
|
|
|
47
|
|
|
$employees[0] = new stdClass(); |
|
|
|
|
48
|
|
|
$employees[0]->id = 1; |
49
|
|
|
$employees[0]->department = 'IT'; |
50
|
|
|
$employees[1] = new stdClass(); |
51
|
|
|
$employees[1]->id = 2; |
52
|
|
|
$employees[1]->department = 'Logistic'; |
53
|
|
|
$response = $this->soapClient->getEmployeesDepartments(array('employeesList' => $employees)); |
54
|
|
|
$this->method('getEmployeesDepartments', array(array('employeesList' => $employees)), $response); |
55
|
|
|
} |
56
|
|
|
} |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.