Rev 1125 | Rev 1189 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1125 | Rev 1130 | ||
---|---|---|---|
Line 30... | Line 30... | ||
30 | \defined('INSIDE_OIDPLUS') or die; |
30 | \defined('INSIDE_OIDPLUS') or die; |
31 | // phpcs:enable PSR1.Files.SideEffects |
31 | // phpcs:enable PSR1.Files.SideEffects |
32 | 32 | ||
33 | class OIDplusRDAP { |
33 | class OIDplusRDAP { |
34 | 34 | ||
- | 35 | /** |
|
- | 36 | * @var string |
|
- | 37 | */ |
|
35 | protected $rdapBaseUri; |
38 | protected $rdapBaseUri; |
- | 39 | ||
- | 40 | /** |
|
- | 41 | * @var bool |
|
- | 42 | */ |
|
36 | protected $useCache; |
43 | protected $useCache; |
- | 44 | ||
- | 45 | /** |
|
- | 46 | * @var string |
|
- | 47 | */ |
|
37 | protected $rdapCacheDir; |
48 | protected $rdapCacheDir; |
- | 49 | ||
- | 50 | /** |
|
- | 51 | * @var int |
|
- | 52 | */ |
|
38 | protected $rdapCacheExpires; |
53 | protected $rdapCacheExpires; |
39 | 54 | ||
40 | /** |
55 | /** |
41 | * @throws \ViaThinkSoft\OIDplus\OIDplusException |
56 | * @throws \ViaThinkSoft\OIDplus\OIDplusException |
42 | */ |
57 | */ |
Line 50... | Line 65... | ||
50 | /** |
65 | /** |
51 | * @param string $query |
66 | * @param string $query |
52 | * @return array |
67 | * @return array |
53 | * @throws \ViaThinkSoft\OIDplus\OIDplusException |
68 | * @throws \ViaThinkSoft\OIDplus\OIDplusException |
54 | */ |
69 | */ |
55 | public function rdapQuery(string $query) { |
70 | public function rdapQuery(string $query): array { |
56 | $query = str_replace('oid:.', 'oid:', $query); |
71 | $query = str_replace('oid:.', 'oid:', $query); |
57 | $n = explode(':', $query); |
72 | $n = explode(':', $query); |
58 | if(2>count($n)){ |
73 | if(2>count($n)){ |
59 | array_unshift($n, 'oid'); |
74 | array_unshift($n, 'oid'); |
60 | $query = 'oid:'.$query; |
75 | $query = 'oid:'.$query; |
Line 242... | Line 257... | ||
242 | } |
257 | } |
243 | return $this->rdap_out($out); |
258 | return $this->rdap_out($out); |
244 | } |
259 | } |
245 | 260 | ||
246 | /** |
261 | /** |
247 | * @param $out |
262 | * @param array $out |
248 | * @param $cacheFile |
263 | * @param string $cacheFile |
249 | * @return void |
264 | * @return void |
250 | */ |
265 | */ |
251 | protected function rdap_write_cache($out, $cacheFile){ |
266 | protected function rdap_write_cache(array $out, string $cacheFile){ |
252 | if (!is_string($cacheFile)) return; |
- | |
253 | @file_put_contents($cacheFile, serialize($out)); |
267 | @file_put_contents($cacheFile, serialize($out)); |
254 | } |
268 | } |
255 | 269 | ||
256 | /** |
270 | /** |
257 | * @param $cacheFile |
271 | * @param string $cacheFile |
258 | * @param $rdapCacheExpires |
272 | * @param int $rdapCacheExpires |
259 | * @return array|null |
273 | * @return array|null |
260 | */ |
274 | */ |
261 | protected function rdap_read_cache($cacheFile, $rdapCacheExpires){ |
275 | protected function rdap_read_cache(string $cacheFile, int $rdapCacheExpires){ |
262 | if (is_string($cacheFile) && file_exists($cacheFile) && filemtime($cacheFile) >= time() - $rdapCacheExpires) { |
276 | if (file_exists($cacheFile) && filemtime($cacheFile) >= time() - $rdapCacheExpires) { |
263 | $out = unserialize(file_get_contents($cacheFile)); |
277 | $out = unserialize(file_get_contents($cacheFile)); |
264 | if(is_array($out) || is_object($out)){ |
278 | if(is_array($out) || is_object($out)){ |
265 | return $this->rdap_out($out); |
279 | return $this->rdap_out($out); |
266 | } |
280 | } |
267 | } |
281 | } |
268 | return null; |
282 | return null; |
269 | } |
283 | } |
270 | 284 | ||
271 | /** |
285 | /** |
272 | * @param $out |
286 | * @param array $out |
273 | * @return array |
287 | * @return array |
274 | */ |
288 | */ |
275 | protected function rdap_out($out){ |
289 | protected function rdap_out(array $out): array { |
276 | $out_content = json_encode($out); |
290 | $out_content = json_encode($out); |
277 | $out_type = 'application/rdap+json'; |
291 | $out_type = 'application/rdap+json'; |
278 | return array($out_content, $out_type); |
292 | return array($out_content, $out_type); |
279 | } |
293 | } |
280 | 294 |