Skip to content

Commit ce98b5b

Browse files
authored
Merge pull request #19 from xterr/master
Fixed PhpArray provider to support rates and historicalRates
2 parents 39d1ddf + 68c0c51 commit ce98b5b

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

DependencyInjection/Configuration.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,28 @@ public function getConfigTreeBuilder()
144144
return true;
145145
}
146146

147-
foreach ($config as $entry) {
148-
if (!is_array($entry) || empty($entry)) {
149-
return true;
150-
}
147+
if (!$this->validateArrayProviderEntry($config)) {
148+
return true;
149+
}
150+
151+
return false;
152+
})
153+
->thenInvalid('Invalid configuration for array provider.')
154+
->end()
155+
->end()
156+
->variableNode('historicalRates')
157+
->treatFalseLike(null)
158+
->treatTrueLike(null)
159+
->isRequired()
160+
->cannotBeEmpty()
161+
->validate()
162+
->ifTrue(function($config) {
163+
if (!is_array($config) || empty($config)) {
164+
return true;
165+
}
151166

152-
if (!$this->validateArrayProviderEntry($entry)) {
153-
return true;
154-
}
167+
if (!$this->validateArrayProviderEntry($config)) {
168+
return true;
155169
}
156170

157171
return false;

Resources/doc/index.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,9 @@ florianv_swap:
6666
token: secret
6767
array:
6868
rates:
69-
-
7069
'EUR/GBP': 1.5
7170
'EUR/USD': 1.1
72-
-
71+
historicalRates:
7372
'2017-01-01':
7473
'EUR/GBP': 1.5
7574
'EUR/USD': 1.1

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,15 @@ public function provideValidProvidersConfigs()
127127
[[
128128
'array' => [
129129
'rates' => [
130-
[
131-
'EUR/USD' => 1.1,
132-
'EUR/GBP' => 1.5,
130+
'EUR/USD' => 1.1,
131+
'EUR/GBP' => 1.5,
132+
],
133+
'historicalRates' => [
134+
'2017-01-01' => [
135+
'EUR/USD' => 1.5,
133136
],
134-
[
135-
'2017-01-01' => [
136-
'EUR/USD' => 1.5,
137-
],
138-
'2017-01-03' => [
139-
'EUR/GBP' => 1.3,
140-
],
137+
'2017-01-03' => [
138+
'EUR/GBP' => 1.3,
141139
],
142140
],
143141
],

0 commit comments

Comments
 (0)