1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CedricZiel\ShariffBundle\Model; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Configures the shariff backend |
7
|
|
|
* |
8
|
|
|
* @package CedricZiel\ShariffBundle |
9
|
|
|
*/ |
10
|
|
|
class ShariffConfig |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
protected $domain; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $forceProtocol; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected $cacheDir; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var int |
29
|
|
|
*/ |
30
|
|
|
protected $cacheTtl; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var array |
34
|
|
|
*/ |
35
|
|
|
protected $services; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var array |
39
|
|
|
*/ |
40
|
|
|
protected $serviceConfig = []; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
protected $adapter; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var array |
49
|
|
|
*/ |
50
|
|
|
protected $adapterOptions; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var array |
54
|
|
|
*/ |
55
|
|
|
protected $client; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param string $domain |
59
|
|
|
* @param boolean $forceProtocol |
60
|
|
|
* @param array $services |
61
|
|
|
* @param string $cache |
62
|
|
|
* @param string $client |
63
|
|
|
*/ |
64
|
|
|
public function __construct($domain, $forceProtocol, $services, $cache, $client) |
65
|
|
|
{ |
66
|
|
|
$this->domain = $domain; |
67
|
|
|
$this->forceProtocol = $forceProtocol; |
|
|
|
|
68
|
|
|
$this->services = array_keys($services); |
69
|
|
|
$this->cacheTtl = $cache['ttl']; |
|
|
|
|
70
|
|
|
$this->cacheDir = isset($cache['cacheDir']) ? $cache['cacheDir'] : null; |
71
|
|
|
$this->adapter = isset($cache['adapter']) ? $cache['adapter'] : null; |
72
|
|
|
$this->adapterOptions = isset($cache['adapterOptions']) ? $cache['adapterOptions'] : null; |
|
|
|
|
73
|
|
|
|
74
|
|
|
foreach ($services as $name => $serviceConfig) { |
75
|
|
|
if (null !== $serviceConfig) { |
76
|
|
|
$this->serviceConfig[$name] = $serviceConfig; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
$this->client = $client; |
|
|
|
|
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return string |
84
|
|
|
*/ |
85
|
|
|
public function getCacheDir() |
86
|
|
|
{ |
87
|
|
|
return $this->cacheDir; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param string $cacheDir |
92
|
|
|
*/ |
93
|
|
|
public function setCacheDir($cacheDir) |
94
|
|
|
{ |
95
|
|
|
$this->cacheDir = $cacheDir; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return int |
100
|
|
|
*/ |
101
|
|
|
public function getCacheTtl() |
102
|
|
|
{ |
103
|
|
|
return $this->cacheTtl; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @param int $cacheTtl |
108
|
|
|
*/ |
109
|
|
|
public function setCacheTtl($cacheTtl) |
110
|
|
|
{ |
111
|
|
|
$this->cacheTtl = $cacheTtl; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return string |
116
|
|
|
*/ |
117
|
|
|
public function getDomain() |
118
|
|
|
{ |
119
|
|
|
return $this->domain; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param string $domain |
124
|
|
|
*/ |
125
|
|
|
public function setDomain($domain) |
126
|
|
|
{ |
127
|
|
|
$this->domain = $domain; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @return string |
132
|
|
|
*/ |
133
|
|
|
public function getForceProtocol() |
134
|
|
|
{ |
135
|
|
|
return $this->forceProtocol; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @param string $forceProtocol |
140
|
|
|
*/ |
141
|
|
|
public function setForceProtocol($forceProtocol) |
142
|
|
|
{ |
143
|
|
|
$this->forceProtocol = $forceProtocol; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @return array |
148
|
|
|
*/ |
149
|
|
|
public function getServices() |
150
|
|
|
{ |
151
|
|
|
return $this->services; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @param array $services |
156
|
|
|
*/ |
157
|
|
|
public function setServices($services) |
158
|
|
|
{ |
159
|
|
|
$this->services = $services; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @return string |
164
|
|
|
*/ |
165
|
|
|
public function getAdapter() |
166
|
|
|
{ |
167
|
|
|
return $this->adapter; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @param string $adapter |
172
|
|
|
*/ |
173
|
|
|
public function setAdapter($adapter) |
174
|
|
|
{ |
175
|
|
|
$this->adapter = $adapter; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @return array |
180
|
|
|
*/ |
181
|
|
|
public function getAdapterOptions() |
182
|
|
|
{ |
183
|
|
|
return $this->adapterOptions; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @param array $adapterOptions |
188
|
|
|
*/ |
189
|
|
|
public function setAdapterOptions($adapterOptions) |
190
|
|
|
{ |
191
|
|
|
$this->adapterOptions = $adapterOptions; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @return array |
196
|
|
|
*/ |
197
|
|
|
public function toArray() |
198
|
|
|
{ |
199
|
|
|
$result = []; |
200
|
|
|
$result['domains'][] = $this->domain; |
201
|
|
|
$result['force_protocol'] = $this->forceProtocol; |
202
|
|
|
$result['services'] = $this->services; |
203
|
|
|
$result = array_merge($result, $this->serviceConfig); |
204
|
|
|
|
205
|
|
|
$result['services'] = array_filter( |
206
|
|
|
$result['services'], |
207
|
|
|
function ($v) { |
208
|
|
|
return 'Twitter' != $v && 'Mail' != $v; |
209
|
|
|
} |
210
|
|
|
); |
211
|
|
|
|
212
|
|
|
$result['cache'] = ['ttl' => $this->cacheTtl]; |
213
|
|
|
if (null !== $this->cacheDir) { |
214
|
|
|
$result['cache']['cacheDir'] = $this->cacheDir; |
215
|
|
|
} |
216
|
|
|
if (null !== $this->adapter) { |
217
|
|
|
$result['cache']['adapter'] = $this->adapter; |
218
|
|
|
} |
219
|
|
|
if (null !== $this->adapterOptions) { |
220
|
|
|
$result['cache']['adapterOptions'] = $this->adapterOptions; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
if (null !== $this->client && count($this->client)) { |
224
|
|
|
$result['client'] = $this->client; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
return $result; |
228
|
|
|
} |
229
|
|
|
} |
230
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.