1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the Exchange Rate Bundle, an RunOpenCode project. |
4
|
|
|
* |
5
|
|
|
* (c) 2016 RunOpenCode |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
namespace RunOpenCode\Bundle\ExchangeRate\Command; |
11
|
|
|
|
12
|
|
|
use RunOpenCode\ExchangeRate\Configuration; |
13
|
|
|
use RunOpenCode\ExchangeRate\Contract\ProcessorInterface; |
14
|
|
|
use RunOpenCode\ExchangeRate\Contract\ProcessorsRegistryInterface; |
15
|
|
|
use RunOpenCode\ExchangeRate\Contract\RatesConfigurationRegistryInterface; |
16
|
|
|
use RunOpenCode\ExchangeRate\Contract\RepositoryInterface; |
17
|
|
|
use RunOpenCode\ExchangeRate\Contract\SourceInterface; |
18
|
|
|
use RunOpenCode\ExchangeRate\Contract\SourcesRegistryInterface; |
19
|
|
|
use Symfony\Component\Console\Command\Command; |
20
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
21
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
22
|
|
|
use Symfony\Component\Console\Style\OutputStyle; |
23
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Class ConfigurationDebugCommand |
27
|
|
|
* |
28
|
|
|
* Display current exchange rate configuration. |
29
|
|
|
* |
30
|
|
|
* @package RunOpenCode\Bundle\ExchangeRate\Command |
31
|
|
|
*/ |
32
|
|
|
class ConfigurationDebugCommand extends Command |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* @var SourcesRegistryInterface |
36
|
|
|
*/ |
37
|
|
|
protected $sourcesRegistry; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var ProcessorsRegistryInterface |
41
|
|
|
*/ |
42
|
|
|
protected $processorsRegistry; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var RatesConfigurationRegistryInterface |
46
|
|
|
*/ |
47
|
|
|
protected $ratesConfigurationRegistry; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var RepositoryInterface |
51
|
|
|
*/ |
52
|
|
|
protected $repository; |
53
|
|
|
|
54
|
|
|
public function __construct( |
55
|
|
|
SourcesRegistryInterface $sourcesRegistry, |
56
|
|
|
ProcessorsRegistryInterface $processorsRegistry, |
57
|
|
|
RatesConfigurationRegistryInterface $ratesConfigurationRegistry, |
58
|
|
|
RepositoryInterface $repository |
59
|
|
|
) { |
60
|
|
|
parent::__construct(); |
61
|
|
|
$this->sourcesRegistry = $sourcesRegistry; |
62
|
|
|
$this->processorsRegistry = $processorsRegistry; |
63
|
|
|
$this->ratesConfigurationRegistry = $ratesConfigurationRegistry; |
64
|
|
|
$this->repository = $repository; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritdoc} |
69
|
|
|
*/ |
70
|
|
|
protected function configure() |
71
|
|
|
{ |
72
|
|
|
$this |
73
|
|
|
->setName('roc:exchange-rate:configuration-debug') |
74
|
|
|
->setDescription('Dump current configuration.') |
75
|
|
|
; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* {@inheritdoc} |
80
|
|
|
*/ |
81
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
82
|
|
|
{ |
83
|
|
|
$outputStyle = new SymfonyStyle($input, $output); |
84
|
|
|
|
85
|
|
|
$outputStyle->title('Displaying current configuration for currency exchange bundle'); |
86
|
|
|
|
87
|
|
|
$this |
88
|
|
|
->displaySources($outputStyle) |
89
|
|
|
->displayNewLine($outputStyle) |
90
|
|
|
->displayProcessors($outputStyle) |
91
|
|
|
->displayNewLine($outputStyle) |
92
|
|
|
->displayRepository($outputStyle) |
93
|
|
|
->displayNewLine($outputStyle) |
94
|
|
|
->displayRates($outputStyle) |
95
|
|
|
->displayNewLine($outputStyle) |
96
|
|
|
; |
97
|
|
|
|
98
|
|
|
$outputStyle |
99
|
|
|
->success('Configuration is valid.'); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Display sources. |
104
|
|
|
* |
105
|
|
|
* @param OutputStyle $outputStyle Console output style. |
106
|
|
|
* @return ConfigurationDebugCommand $this |
107
|
|
|
*/ |
108
|
|
|
protected function displaySources(OutputStyle $outputStyle) |
109
|
|
|
{ |
110
|
|
|
$outputStyle->section('Sources:'); |
111
|
|
|
/** |
112
|
|
|
* @var SourceInterface $source |
113
|
|
|
*/ |
114
|
|
|
foreach ($this->sourcesRegistry as $source) { |
115
|
|
|
$outputStyle->writeln(' -> ' . sprintf('%s as %s', get_class($source), $source->getName())); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
return $this; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Display processors. |
123
|
|
|
* |
124
|
|
|
* @param OutputStyle $outputStyle Console output style. |
125
|
|
|
* @return ConfigurationDebugCommand $this |
126
|
|
|
*/ |
127
|
|
|
protected function displayProcessors(OutputStyle $outputStyle) |
128
|
|
|
{ |
129
|
|
|
$outputStyle->section('Processors:'); |
130
|
|
|
/** |
131
|
|
|
* @var ProcessorInterface $processor |
132
|
|
|
*/ |
133
|
|
|
foreach ($this->processorsRegistry as $processor) { |
134
|
|
|
$outputStyle->writeln(' -> ' . get_class($processor)); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
return $this; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Display repository. |
142
|
|
|
* |
143
|
|
|
* @param OutputStyle $outputStyle Console output style. |
144
|
|
|
* @return ConfigurationDebugCommand $this |
145
|
|
|
*/ |
146
|
|
|
protected function displayRepository(OutputStyle $outputStyle) |
147
|
|
|
{ |
148
|
|
|
$outputStyle->section('Repository:'); |
149
|
|
|
|
150
|
|
|
$outputStyle->writeln(' -> '. sprintf('%s with %s record(s).', get_class($this->repository), $this->repository->count())); |
151
|
|
|
|
152
|
|
|
return $this; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Display rates. |
157
|
|
|
* |
158
|
|
|
* @param OutputStyle $outputStyle Console output style. |
159
|
|
|
* @return ConfigurationDebugCommand $this |
160
|
|
|
*/ |
161
|
|
|
protected function displayRates(OutputStyle $outputStyle) |
162
|
|
|
{ |
163
|
|
|
$outputStyle->section('Registered exchange rates:'); |
164
|
|
|
|
165
|
|
|
$headers = array('Currency code', 'Rate type', 'Source'); |
166
|
|
|
|
167
|
|
|
$rows = array(); |
168
|
|
|
/** |
169
|
|
|
* @var Configuration $rateConfiguration |
170
|
|
|
*/ |
171
|
|
|
foreach ($this->ratesConfigurationRegistry as $rateConfiguration) { |
172
|
|
|
$rows[] = array( |
173
|
|
|
$rateConfiguration->getCurrencyCode(), |
174
|
|
|
$rateConfiguration->getRateType(), |
175
|
|
|
$rateConfiguration->getSourceName() |
176
|
|
|
); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
$outputStyle->table($headers, $rows); |
180
|
|
|
|
181
|
|
|
return $this; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Display new line. |
187
|
|
|
* |
188
|
|
|
* @param OutputStyle $outputStyle Console output style. |
189
|
|
|
* @return ConfigurationDebugCommand $this |
190
|
|
|
*/ |
191
|
|
|
protected function displayNewLine(OutputStyle $outputStyle) |
192
|
|
|
{ |
193
|
|
|
$outputStyle->newLine(); |
194
|
|
|
return $this; |
195
|
|
|
} |
196
|
|
|
} |
197
|
|
|
|