1
|
|
|
<?php |
2
|
|
|
namespace Clients; |
3
|
|
|
|
4
|
|
|
use DOMDocument; |
5
|
|
|
use SoapClient; |
6
|
|
|
use Symfony\Component\Console\Command\Command; |
7
|
|
|
use Symfony\Component\Console\Formatter\OutputFormatterStyle; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
|
10
|
|
|
class InitCommand extends Command |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var OutputInterface |
14
|
|
|
*/ |
15
|
|
|
protected $output; |
16
|
|
|
/** |
17
|
|
|
* @var SoapClient |
18
|
|
|
*/ |
19
|
|
|
protected $soapClient; |
20
|
|
|
|
21
|
|
|
public function __construct() |
22
|
|
|
{ |
23
|
|
|
parent::__construct(); |
24
|
|
|
ini_set("soap.wsdl_cache_enabled", 0); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
protected function method($method, $requestParams, $response) |
28
|
|
|
{ |
29
|
|
|
$this->separator(); |
30
|
|
|
|
31
|
|
|
$this->output->writeln('Method <info>' . $method . '</info>:'); |
32
|
|
|
$this->output->writeln(''); |
33
|
|
|
|
34
|
|
|
$this->output->writeln('<comment>Request params:</comment>'); |
35
|
|
|
$output = $this->output; |
36
|
|
|
array_walk($requestParams, function ($param, $key) use ($output) { |
37
|
|
|
$output->writeln('Param ' . ($key + 1) . ':'); |
38
|
|
|
var_dump($param); |
|
|
|
|
39
|
|
|
$output->writeln(''); |
40
|
|
|
}); |
41
|
|
|
|
42
|
|
|
$this->output->writeln('<comment>Response:</comment>'); |
43
|
|
|
print_r($response); |
44
|
|
|
$this->output->writeln(''); |
45
|
|
|
$this->output->writeln(''); |
46
|
|
|
|
47
|
|
|
$DOMDocument = new DOMDocument(); |
48
|
|
|
$DOMDocument->formatOutput = true; |
49
|
|
|
|
50
|
|
|
$this->output->writeln('<comment>Request headers:</comment>'); |
51
|
|
|
$DOMDocument->loadXML($this->soapClient->__getLastRequest()); |
52
|
|
|
$this->output->writeln($DOMDocument->saveXML()); |
53
|
|
|
|
54
|
|
|
$this->output->writeln('<comment>Response headers:</comment>'); |
55
|
|
|
$DOMDocument->loadXML($this->soapClient->__getLastResponse()); |
56
|
|
|
$this->output->writeln($DOMDocument->saveXML()); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
protected function separator() |
60
|
|
|
{ |
61
|
|
|
return $this->output->writeln("\n---------\n"); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
protected function renderMethodsTable() |
65
|
|
|
{ |
66
|
|
|
$table = $this->getHelper('table'); |
67
|
|
|
$table->setHeaders(array('Method name')); |
68
|
|
|
$table->setRows($this->_getRows()); |
69
|
|
|
$table->render($this->output); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
private function _getRows() |
73
|
|
|
{ |
74
|
|
|
return array_map(function ($function) { |
75
|
|
|
return array($function); |
76
|
|
|
}, $this->soapClient->__getFunctions()); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
protected function serviceInfo($name) |
80
|
|
|
{ |
81
|
|
|
$style = new OutputFormatterStyle('red', 'green', array('bold')); |
82
|
|
|
$this->output->getFormatter()->setStyle('header', $style); |
83
|
|
|
$this->output->writeln("<header>\n\t$name\n</header>"); |
84
|
|
|
} |
85
|
|
|
} |