-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShariffConfig.php
201 lines (167 loc) · 4.07 KB
/
ShariffConfig.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php
/**
* www.valiton.com
*
* @author Uwe Jäger <[email protected]>
*/
namespace Valiton\Bundle\ShariffBundle;
class ShariffConfig
{
/** @var string */
protected $domain;
/** @var string */
protected $force_protocol;
/** @var string */
protected $cacheDir;
/** @var int */
protected $cacheTtl;
/** @var array */
protected $services;
/** @var array */
protected $serviceConfig = array();
/** @var string */
protected $adapter;
/** @var array */
protected $adapterOptions;
/** @var array */
protected $client;
public function __construct($domain, $force_protocol, $services, $cache, $client)
{
$this->domain = $domain;
$this->force_protocol = $force_protocol;
$this->services = array_keys($services);
$this->cacheTtl = $cache['ttl'];
$this->cacheDir = isset($cache['cacheDir']) ? $cache['cacheDir'] : null;
$this->adapter = isset($cache['adapter']) ? $cache['adapter'] : null;
$this->adapterOptions = isset($cache['adapterOptions']) ? $cache['adapterOptions'] : null;
foreach($services as $name => $serviceConfig) {
if (null !== $serviceConfig) {
$this->serviceConfig[$name] = $serviceConfig;
}
}
$this->client = $client;
}
/**
* @param string $cacheDir
*/
public function setCacheDir($cacheDir)
{
$this->cacheDir = $cacheDir;
}
/**
* @return string
*/
public function getCacheDir()
{
return $this->cacheDir;
}
/**
* @param int $cacheTtl
*/
public function setCacheTtl($cacheTtl)
{
$this->cacheTtl = $cacheTtl;
}
/**
* @return int
*/
public function getCacheTtl()
{
return $this->cacheTtl;
}
/**
* @param string $domain
*/
public function setDomain($domain)
{
$this->domain = $domain;
}
/**
* @return string
*/
public function getDomain()
{
return $this->domain;
}
/**
* @return string
*/
public function getForceProtocol()
{
return $this->force_protocol;
}
/**
* @param string $force_protocol
*/
public function setForceProtocol($force_protocol)
{
$this->force_protocol = $force_protocol;
}
/**
* @param array $services
*/
public function setServices($services)
{
$this->services = $services;
}
/**
* @return array
*/
public function getServices()
{
return $this->services;
}
/**
* @param string $adapter
*/
public function setAdapter($adapter)
{
$this->adapter = $adapter;
}
/**
* @return string
*/
public function getAdapter()
{
return $this->adapter;
}
/**
* @param array $adapterOptions
*/
public function setAdapterOptions($adapterOptions)
{
$this->adapterOptions = $adapterOptions;
}
/**
* @return array
*/
public function getAdapterOptions()
{
return $this->adapterOptions;
}
public function toArray()
{
$result = array();
$result['domain'] = $this->domain;
$result['force_protocol'] = $this->force_protocol;
$result['services'] = $this->services;
$result = array_merge($result, $this->serviceConfig);
$result['services'] = array_filter($result['services'], function ($v) {
return 'Twitter' != $v;
});
$result['cache'] = array('ttl' => $this->cacheTtl);
if (null !== $this->cacheDir) {
$result['cache']['cacheDir'] = $this->cacheDir;
}
if (null !== $this->adapter) {
$result['cache']['adapter'] = $this->adapter;
}
if (null !== $this->adapterOptions) {
$result['cache']['adapterOptions'] = $this->adapterOptions;
}
if (null !== $this->client && count($this->client)) {
$result['client'] = $this->client;
}
return $result;
}
}