|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* Copyright 2016 Jan Eichhorn <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
6
|
|
|
* you may not use this file except in compliance with the License. |
|
7
|
|
|
* You may obtain a copy of the License at |
|
8
|
|
|
* |
|
9
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
10
|
|
|
* |
|
11
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
12
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
13
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14
|
|
|
* See the License for the specific language governing permissions and |
|
15
|
|
|
* limitations under the License. |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace ApaiIO\Configuration; |
|
19
|
|
|
|
|
20
|
|
|
use ApaiIO\Request\RequestInterface; |
|
21
|
|
|
use ApaiIO\ResponseTransformer\ResponseTransformerInterface; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* A generic configurationclass |
|
25
|
|
|
* |
|
26
|
|
|
* @author Jan Eichhorn <[email protected]> |
|
27
|
|
|
*/ |
|
28
|
|
|
class GenericConfiguration implements ConfigurationInterface |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* The country |
|
32
|
|
|
* |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $country; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* The accesskey |
|
39
|
|
|
* |
|
40
|
|
|
* @var string |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $accessKey; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* The string |
|
46
|
|
|
* |
|
47
|
|
|
* @var string |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $secretKey; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* The associate Tag |
|
53
|
|
|
* |
|
54
|
|
|
* @var string |
|
55
|
|
|
*/ |
|
56
|
|
|
protected $associateTag; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* The requestclass |
|
60
|
|
|
* By default its set to the provided restful request |
|
61
|
|
|
* |
|
62
|
|
|
* @var RequestInterface |
|
63
|
|
|
*/ |
|
64
|
|
|
protected $request; |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* The responsetransformerclass |
|
68
|
|
|
* By default its set to null which means that no transformer will be applied |
|
69
|
|
|
* |
|
70
|
|
|
* @var ResponseTransformerInterface |
|
71
|
|
|
*/ |
|
72
|
|
|
protected $responseTransformer; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* {@inheritdoc} |
|
76
|
|
|
*/ |
|
77
|
3 |
|
public function getCountry() |
|
78
|
|
|
{ |
|
79
|
3 |
|
return $this->country; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Sets and validates the country |
|
84
|
|
|
* |
|
85
|
|
|
* @param string $country |
|
86
|
|
|
* |
|
87
|
|
|
* @return \ApaiIO\Configuration\GenericConfiguration |
|
88
|
|
|
*/ |
|
89
|
4 |
|
public function setCountry($country) |
|
90
|
|
|
{ |
|
91
|
4 |
|
if (!Country::isValidCountry($country)) { |
|
92
|
1 |
|
throw new \InvalidArgumentException( |
|
93
|
1 |
|
sprintf( |
|
94
|
1 |
|
"Invalid Country-Code: %s! Possible Country-Codes: %s", |
|
95
|
1 |
|
$country, |
|
96
|
1 |
|
implode(', ', Country::getCountries()) |
|
97
|
|
|
) |
|
98
|
|
|
); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
3 |
|
$this->country = strtolower($country); |
|
102
|
|
|
|
|
103
|
3 |
|
return $this; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* {@inheritdoc} |
|
108
|
|
|
*/ |
|
109
|
3 |
|
public function getAccessKey() |
|
110
|
|
|
{ |
|
111
|
3 |
|
return $this->accessKey; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Sets the accesskey |
|
116
|
|
|
* |
|
117
|
|
|
* @param string $accessKey |
|
118
|
|
|
* |
|
119
|
|
|
* @return \ApaiIO\Configuration\GenericConfiguration |
|
120
|
|
|
*/ |
|
121
|
3 |
|
public function setAccessKey($accessKey) |
|
122
|
|
|
{ |
|
123
|
3 |
|
$this->accessKey = $accessKey; |
|
124
|
|
|
|
|
125
|
3 |
|
return $this; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* {@inheritdoc} |
|
130
|
|
|
*/ |
|
131
|
3 |
|
public function getSecretKey() |
|
132
|
|
|
{ |
|
133
|
3 |
|
return $this->secretKey; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Sets the secretkey |
|
138
|
|
|
* |
|
139
|
|
|
* @param string $secretKey |
|
140
|
|
|
* |
|
141
|
|
|
* @return \ApaiIO\Configuration\GenericConfiguration |
|
142
|
|
|
*/ |
|
143
|
3 |
|
public function setSecretKey($secretKey) |
|
144
|
|
|
{ |
|
145
|
3 |
|
$this->secretKey = $secretKey; |
|
146
|
|
|
|
|
147
|
3 |
|
return $this; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* {@inheritdoc} |
|
152
|
|
|
*/ |
|
153
|
3 |
|
public function getAssociateTag() |
|
154
|
|
|
{ |
|
155
|
3 |
|
return $this->associateTag; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* Sets the associatetag |
|
160
|
|
|
* |
|
161
|
|
|
* @param string $associateTag |
|
162
|
|
|
* |
|
163
|
|
|
* @return \ApaiIO\Configuration\GenericConfiguration |
|
164
|
|
|
*/ |
|
165
|
3 |
|
public function setAssociateTag($associateTag) |
|
166
|
|
|
{ |
|
167
|
3 |
|
$this->associateTag = $associateTag; |
|
168
|
|
|
|
|
169
|
3 |
|
return $this; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* {@inheritdoc} |
|
174
|
|
|
*/ |
|
175
|
3 |
|
public function getRequest() |
|
176
|
|
|
{ |
|
177
|
3 |
|
return $this->request; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* Sets the Request. |
|
182
|
|
|
* |
|
183
|
|
|
* @param RequestInterface $request |
|
184
|
|
|
* |
|
185
|
|
|
* @return \ApaiIO\Configuration\GenericConfiguration |
|
186
|
|
|
*/ |
|
187
|
3 |
|
public function setRequest(RequestInterface $request) |
|
188
|
|
|
{ |
|
189
|
3 |
|
$this->request = $request; |
|
190
|
|
|
|
|
191
|
3 |
|
return $this; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* {@inheritdoc} |
|
196
|
|
|
*/ |
|
197
|
3 |
|
public function getResponseTransformer() |
|
198
|
|
|
{ |
|
199
|
3 |
|
return $this->responseTransformer; |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* Sets the ResponseTransformer |
|
204
|
|
|
* |
|
205
|
|
|
* @param ResponseTransformerInterface $responseTransformer |
|
206
|
|
|
* |
|
207
|
|
|
* @return \ApaiIO\Configuration\GenericConfiguration |
|
208
|
|
|
*/ |
|
209
|
2 |
|
public function setResponseTransformer(ResponseTransformerInterface $responseTransformer) |
|
210
|
|
|
{ |
|
211
|
2 |
|
$this->responseTransformer = $responseTransformer; |
|
212
|
|
|
|
|
213
|
2 |
|
return $this; |
|
214
|
|
|
} |
|
215
|
|
|
} |
|
216
|
|
|
|