1 | <?php |
||
8 | class FeaturedFlagsImpl implements FeaturedFlags |
||
9 | { |
||
10 | protected $_pdo; |
||
11 | protected $_redis; |
||
12 | protected $_date; |
||
13 | |||
14 | CONST TABLE_NAME = 'featured_flags'; |
||
15 | CONST ISENABLED_PREFIX = 'isEnabled_'; |
||
16 | CONST GETVALUES_PREFIX = 'getEnabledValues_'; |
||
17 | |||
18 | /** |
||
19 | * FeaturedFlags constructor. |
||
20 | * @param PDO $pdo |
||
21 | * @param Redis|null $redis |
||
22 | * @param string|null $date |
||
23 | */ |
||
24 | 25 | public function __construct(PDO $pdo, Redis $redis = null, $date = null) |
|
25 | 1 | { |
|
26 | 25 | $this->_pdo = $pdo; |
|
27 | 25 | if ($redis) { |
|
28 | 25 | $this->_redis = $redis; |
|
29 | 25 | } |
|
30 | 25 | if (!is_null($date)) { |
|
31 | 25 | $this->_date = $date; |
|
32 | 25 | } |
|
33 | 25 | } |
|
34 | |||
35 | /** |
||
36 | * @param PDO $pdo |
||
37 | * @param Redis $redis |
||
38 | * @return FeaturedFlags |
||
39 | */ |
||
40 | 2 | public static function getInstance(PDO $pdo, Redis $redis = null) { |
|
43 | |||
44 | /** |
||
45 | * @param string $flagName |
||
46 | * @param null|array $filterParams |
||
47 | * @return boolean |
||
48 | */ |
||
49 | 16 | public function isEnabled($flagName, $filterParams = null) |
|
62 | |||
63 | /** |
||
64 | * @param string $flagName |
||
65 | * @param null|array $filterParams |
||
66 | * @return array |
||
67 | */ |
||
68 | 7 | public function getEnabledValues($flagName, $filterParams = null) |
|
81 | |||
82 | /** |
||
83 | * @param Redis $redis |
||
84 | */ |
||
85 | 3 | public function setRedis(Redis $redis) |
|
89 | |||
90 | /** |
||
91 | * @param string $flagName |
||
92 | * @param null|array $filterParams |
||
93 | * @return FeaturedFlagsModel |
||
94 | */ |
||
95 | 20 | private function _getBDFlag($flagName, $filterParams) |
|
107 | |||
108 | /** |
||
109 | * @param string $cacheKey |
||
110 | * @return FeaturedFlagsModel |
||
111 | */ |
||
112 | 23 | private function _getCacheModel($cacheKey) |
|
121 | |||
122 | /** |
||
123 | * @param string $cacheKey |
||
124 | * @param FeaturedFlagsModel $featuredFlagsModel |
||
125 | */ |
||
126 | 20 | private function _setCacheKey($cacheKey, FeaturedFlagsModel $featuredFlagsModel) |
|
127 | { |
||
128 | 20 | if (!is_null($this->_redis)) { |
|
129 | 20 | $timeOut = $this->_getTimeout($featuredFlagsModel->getEndDate()); |
|
130 | 20 | $this->_redis->set($cacheKey, $featuredFlagsModel, $timeOut); |
|
131 | 20 | } |
|
132 | 20 | } |
|
133 | |||
134 | /** |
||
135 | * @param string $query |
||
136 | * @param array $params |
||
137 | * @return \mysqli_stmt |
||
138 | */ |
||
139 | 20 | private function _getStmt($query, $params) |
|
147 | |||
148 | /** |
||
149 | * @param string $flagName |
||
150 | * @return array |
||
151 | */ |
||
152 | 20 | private function _getDBFlagsData($flagName) |
|
173 | |||
174 | /** |
||
175 | * @param string $query |
||
176 | * @param array $params |
||
177 | * @return array |
||
178 | */ |
||
179 | 20 | private function _executeForSelect($query, $params = array()) |
|
185 | |||
186 | /** |
||
187 | * @return string |
||
188 | */ |
||
189 | 20 | private function _getDate() { |
|
196 | |||
197 | /** |
||
198 | * @param array $flagParams |
||
199 | * @param array $filterParams |
||
200 | * @return boolean |
||
201 | */ |
||
202 | 7 | private function _compareParams($flagParams, $filterParams) |
|
212 | |||
213 | /** |
||
214 | * @param string $flagParamsJson |
||
215 | * @param null|array $filterParams |
||
216 | * @return boolean |
||
217 | */ |
||
218 | 13 | private function _checkParams($flagParamsJson, $filterParams = null) |
|
231 | |||
232 | /** |
||
233 | * @param string $flagName |
||
234 | * @param array|null $filterParams |
||
235 | * @param string $prefix |
||
236 | * @return boolean |
||
237 | */ |
||
238 | 23 | private function _getKey($flagName, $filterParams = null, $prefix = "") |
|
242 | |||
243 | /** |
||
244 | * @param string $endDate |
||
245 | * @return int |
||
246 | */ |
||
247 | 20 | private function _getTimeout($endDate) |
|
255 | } |
||
256 |