| | @@ -37,14 +37,15 @@ |
| 37 | 37 | */
|
| 38 | 38 | namespace Std\Lib;
|
| 39 | 39 |
|
| 40 | +use Std\Lib\Cache;
|
| 40 | 41 | use Std\Lib\Curl;
|
| 41 | 42 | use Result;
|
| 42 | 43 |
|
| 43 | 44 | class Openprovider {
|
| 44 | | - protected string $dataDir = ROOT."/data/cache/openprovider/";
|
| 45 | + protected string $cacheDir = ROOT."/data/cache/openprovider/";
|
| 45 | 46 | protected int $tokenDuration = 172800; // 48時間
|
| 46 | | - protected int $dataDuration = 1800; // 30分
|
| 47 | 47 |
|
| 48 | + private Cache $cache;
|
| 48 | 49 | private string $user = '';
|
| 49 | 50 | private string $pass = '';
|
| 50 | 51 | private string $token = '';
|
| | @@ -59,6 +60,7 @@ |
| 59 | 60 | $this->user = OPENPROVIDER['username'];
|
| 60 | 61 | $this->pass = OPENPROVIDER['password'];
|
| 61 | 62 | $this->ip = OPENPROVIDER['ip'];
|
| 63 | + $this->cache = new Cache($this->cacheDir);
|
| 62 | 64 | }
|
| 63 | 65 |
|
| 64 | 66 | /**
|
| | @@ -70,7 +72,7 @@ |
| 70 | 72 | public function login(): Result {
|
| 71 | 73 | if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
|
| 72 | 74 | $cacheName = 'login';
|
| 73 | | - $cache = $this->getCache($cacheName);
|
| 75 | + $cache = $this->cache->get($cacheName);
|
| 74 | 76 | if (time() < ($this->lastAuth + $this->tokenDuration)) {
|
| 75 | 77 | $this->token = $cache['data']['token'];
|
| 76 | 78 | $this->lastAuth = $cache['last_auth'];
|
| | @@ -110,7 +112,7 @@ |
| 110 | 112 | $this->token = $res['data']['token'];
|
| 111 | 113 | $this->lastAuth = time();
|
| 112 | 114 | $res['last_auth'] = $this->lastAuth;
|
| 113 | | - $this->setCache($cacheName, $res);
|
| 115 | + $this->cache->set($cacheName, $res);
|
| 114 | 116 |
|
| 115 | 117 | return Result::Success('', $res);
|
| 116 | 118 | }
|
| | @@ -150,14 +152,14 @@ |
| 150 | 152 | */
|
| 151 | 153 | public function listDomains(array $query = []): Result {
|
| 152 | 154 | if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
|
| 153 | | - $cacheName = 'listdomains'
|
| 154 | | - $cache = $this->getCache($cacheName);
|
| 155 | | - if ($this->isValidLifespan($cache, $query)) return Result::Success('', $cache);
|
| 155 | + $cacheName = 'listdomains';
|
| 156 | + $cache = $this->cache->get($cacheName);
|
| 157 | + if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
|
| 156 | 158 |
|
| 157 | 159 | $curl = $this->setupCurl('/domains');
|
| 158 | 160 | $res = $this->curlResult($curl);
|
| 159 | 161 | if (isset($res['data']['results'])) {
|
| 160 | | - $this->setCache($cacheName, $res->data);
|
| 162 | + $this->cache->set($cacheName, $res->data);
|
| 161 | 163 | return Result::Success('', $res['data']['results']);
|
| 162 | 164 | }
|
| 163 | 165 |
|
| | @@ -271,14 +273,14 @@ |
| 271 | 273 | if (isset($query['domain.extension'])) $ext = $query['domain.extension'];
|
| 272 | 274 | $cacheName = $name && $ext ? "domainadditionaldata-{$name}.{$ext}" : 'domainadditionaldata';
|
| 273 | 275 |
|
| 274 | | - $cache = $this->getCache($cacheName);
|
| 275 | | - if ($this->isValidLifespan($cache)) return Result::Success('', $cache);
|
| 276 | + $cache = $this->cache->get($cacheName);
|
| 277 | + if ($this->cache->validate($cache)) return Result::Success('', $cache);
|
| 276 | 278 |
|
| 277 | 279 | $uri = "/domains/additional-data?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
|
| 278 | 280 | $curl = $this->setupCurl($uri);
|
| 279 | 281 | $res = $this->curlResult($curl);
|
| 280 | 282 | if (isset($res->data['data'])) {
|
| 281 | | - $this->setCache($cacheName, $res->data);
|
| 283 | + $this->cache->set($cacheName, $res->data);
|
| 282 | 284 | return Result::Success('', $res->data);
|
| 283 | 285 | }
|
| 284 | 286 |
|
| | @@ -302,14 +304,14 @@ |
| 302 | 304 | if (isset($query['domain.extension'])) $ext = $query['domain.extension'];
|
| 303 | 305 | $cacheName = $name && $ext ? "domainadditionaldata-{$name}.{$ext}" : 'domainadditionaldata';
|
| 304 | 306 |
|
| 305 | | - $cache = $this->getCache($cacheName);
|
| 306 | | - if ($this->isValidLifespan($cache)) return Result::Success('', $cache);
|
| 307 | + $cache = $this->cache->get($cacheName);
|
| 308 | + if ($this->cache->validate($cache)) return Result::Success('', $cache);
|
| 307 | 309 |
|
| 308 | 310 | $uri = "/domains/additional-data/customers?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
|
| 309 | 311 | $curl = $this->setupCurl($uri);
|
| 310 | 312 | $res = $this->curlResult($curl);
|
| 311 | 313 | if (isset($res->data['data'])) {
|
| 312 | | - $this->setCache($cacheName, $res->data);
|
| 314 | + $this->cache->set($cacheName, $res->data);
|
| 313 | 315 | return Result::Success('', $res->data);
|
| 314 | 316 | }
|
| 315 | 317 |
|
| | @@ -333,14 +335,14 @@ |
| 333 | 335 | if (isset($query['domain.extension'])) $ext = $query['domain.extension'];
|
| 334 | 336 | $cacheName = $name && $ext ? "domainprices-{$name}.{$ext}" : 'domainprices';
|
| 335 | 337 |
|
| 336 | | - $cache = $this->getCache($cacheName);
|
| 337 | | - if ($this->isValidLifespan($cache)) return Result::Success('', $cache);
|
| 338 | + $cache = $this->cache->get($cacheName);
|
| 339 | + if ($this->cache->validate($cache)) return Result::Success('', $cache);
|
| 338 | 340 |
|
| 339 | 341 | $uri = "/domains/prices?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
|
| 340 | 342 | $curl = $this->setupCurl($uri);
|
| 341 | 343 | $res = $this->curlResult($curl);
|
| 342 | 344 | if (isset($res->data['data'])) {
|
| 343 | | - $this->setCache($cacheName, $res->data);
|
| 345 | + $this->cache->set($cacheName, $res->data);
|
| 344 | 346 | return Result::Success('', $res->data);
|
| 345 | 347 | }
|
| 346 | 348 |
|
| | @@ -403,8 +405,8 @@ |
| 403 | 405 | public function listTlds(array $query = []): Result {
|
| 404 | 406 | if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
|
| 405 | 407 | $cacheName = 'listtlds';
|
| 406 | | - $cache = $this->getCache($cacheName);
|
| 407 | | - if ($this->isValidLifespan($cache)) return Result::Success('', $cache);
|
| 408 | + $cache = $this->cache->get($cacheName);
|
| 409 | + if ($this->cache->validate($cache)) return Result::Success('', $cache);
|
| 408 | 410 |
|
| 409 | 411 | if (empty($query)) $query = [ 'limit' => 10, 'offset' => 0, 'order' => 'ASC' ];
|
| 410 | 412 | foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
|
| | @@ -413,7 +415,7 @@ |
| 413 | 415 | $curl = $this->setupCurl($uri);
|
| 414 | 416 | $res = $this->curlResult($curl);
|
| 415 | 417 | if (isset($res->data['data'])) {
|
| 416 | | - $this->setCache($cacheName, $res->data);
|
| 418 | + $this->cache->set($cacheName, $res->data);
|
| 417 | 419 | return Result::Success('', $res->data);
|
| 418 | 420 | }
|
| 419 | 421 |
|
| | @@ -430,8 +432,8 @@ |
| 430 | 432 | public function getTld(string $tld, array $query = []): Result {
|
| 431 | 433 | if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
|
| 432 | 434 | $cacheName = "gettld-{$tld}";
|
| 433 | | - $cache = $this->getCache($cacheName);
|
| 434 | | - if ($this->isValidLifespan($cache)) return Result::Success('', $cache);
|
| 435 | + $cache = $this->cache->get($cacheName);
|
| 436 | + if ($this->cache->validate($cache)) return Result::Success('', $cache);
|
| 435 | 437 |
|
| 436 | 438 | if (empty($query)) $query = [ 'limit' => 10, 'offset' => 0 ];
|
| 437 | 439 | foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
|
| | @@ -440,7 +442,7 @@ |
| 440 | 442 | $curl = $this->setupCurl($uri);
|
| 441 | 443 | $res = $this->curlResult($curl);
|
| 442 | 444 | if (isset($res->data['data'])) {
|
| 443 | | - $this->setCache($cacheName, $res->data);
|
| 445 | + $this->cache->set($cacheName, $res->data);
|
| 444 | 446 | return Result::Success('', $res->data);
|
| 445 | 447 | }
|
| 446 | 448 |
|
| | @@ -460,8 +462,8 @@ |
| 460 | 462 | public function listInvoices(array $query = []): Result {
|
| 461 | 463 | if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
|
| 462 | 464 | $cacheName = 'listinvoices';
|
| 463 | | - $cache = $this->getCache($cacheName);
|
| 464 | | - if ($this->isValidLifespan($cache)) return Result::Success('', $cache);
|
| 465 | + $cache = $this->cache->get($cacheName);
|
| 466 | + if ($this->cache->validate($cache)) return Result::Success('', $cache);
|
| 465 | 467 |
|
| 466 | 468 | if (empty($query)) $query = [ 'limit' => 10, 'offset' => 0 ];
|
| 467 | 469 | foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
|
| | @@ -470,7 +472,7 @@ |
| 470 | 472 | $curl = $this->setupCurl($uri);
|
| 471 | 473 | $res = $this->curlResult($curl);
|
| 472 | 474 | if (isset($res->data['data'])) {
|
| 473 | | - $this->setCache($cacheName, $res->data);
|
| 475 | + $this->cache->set($cacheName, $res->data);
|
| 474 | 476 | return Result::Success('', $res->data);
|
| 475 | 477 | }
|
| 476 | 478 |
|
| | @@ -489,8 +491,8 @@ |
| 489 | 491 | public function listPayments(array $query = []): Result {
|
| 490 | 492 | if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
|
| 491 | 493 | $cacheName = 'listpayments';
|
| 492 | | - $cache = $this->getCache($cacheName);
|
| 493 | | - if ($this->isValidLifespan($cache)) return Result::Success('', $cache);
|
| 494 | + $cache = $this->cache->get($cacheName);
|
| 495 | + if ($this->cache->validate($cache)) return Result::Success('', $cache);
|
| 494 | 496 |
|
| 495 | 497 | if (empty($query)) $query = [ 'limit' => 10, 'offset' => 0 ];
|
| 496 | 498 | foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
|
| | @@ -499,7 +501,7 @@ |
| 499 | 501 | $curl = $this->setupCurl($uri);
|
| 500 | 502 | $res = $this->curlResult($curl);
|
| 501 | 503 | if (isset($res->data['data'])) {
|
| 502 | | - $this->setCache($cacheName, $res->data);
|
| 504 | + $this->cache->set($cacheName, $res->data);
|
| 503 | 505 | return Result::Success('', $res->data);
|
| 504 | 506 | }
|
| 505 | 507 |
|
| | @@ -518,8 +520,8 @@ |
| 518 | 520 | public function listTransactions(array $query = []): Result {
|
| 519 | 521 | if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
|
| 520 | 522 | $cacheName = 'listtransactions';
|
| 521 | | - $cache = $this->getCache($cacheName);
|
| 522 | | - if ($this->isValidLifespan($cache)) return Result::Success('', $cache);
|
| 523 | + $cache = $this->cache->get($cacheName);
|
| 524 | + if ($this->cache->validate($cache)) return Result::Success('', $cache);
|
| 523 | 525 |
|
| 524 | 526 | if (empty($query)) $query = [ 'limit' => 10, 'offset' => 0 ];
|
| 525 | 527 | foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
|
| | @@ -528,7 +530,7 @@ |
| 528 | 530 | $curl = $this->setupCurl($uri);
|
| 529 | 531 | $res = $this->curlResult($curl);
|
| 530 | 532 | if (isset($res->data['data'])) {
|
| 531 | | - $this->setCache($cacheName, $res->data);
|
| 533 | + $this->cache->set($cacheName, $res->data);
|
| 532 | 534 | return Result::Success('', $res->data);
|
| 533 | 535 | }
|
| 534 | 536 |
|
| | @@ -570,8 +572,8 @@ |
| 570 | 572 | public function listNameservers(array $query = []): Result {
|
| 571 | 573 | if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
|
| 572 | 574 | $cacheName = 'listnameservers';
|
| 573 | | - $cache = $this->getCache($cacheName);
|
| 574 | | - if ($this->isValidLifespan($cache, $query)) return Result::Success('', $cache);
|
| 575 | + $cache = $this->cache->get($cacheName);
|
| 576 | + if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
|
| 575 | 577 |
|
| 576 | 578 | if (empty($query)) $query = [ 'limit' => 25, 'offset' => 0, 'order_by.name' => 'asc' ];
|
| 577 | 579 | foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
|
| | @@ -580,7 +582,7 @@ |
| 580 | 582 | $curl = $this->setupCurl($uri);
|
| 581 | 583 | $res = $this->curlResult($curl);
|
| 582 | 584 | if (isset($res->data['data'])) {
|
| 583 | | - $this->setCache($cacheName, $res->data);
|
| 585 | + $this->cache->set($cacheName, $res->data);
|
| 584 | 586 | return Result::Success('', $res->data);
|
| 585 | 587 | }
|
| 586 | 588 |
|
| | @@ -601,7 +603,7 @@ |
| 601 | 603 | $curl = $this->setupCurl($uri, 'POST', $payload);
|
| 602 | 604 | $res = $this->curlResult($curl);
|
| 603 | 605 | if (isset($res->data['data'])) {
|
| 604 | | - $this->murderCache('listnameservers');
|
| 606 | + $this->cache->murder('listnameservers');
|
| 605 | 607 | return Result::Success('ネームサーバーの追加に成功。', $res->data);
|
| 606 | 608 | }
|
| 607 | 609 |
|
| | @@ -619,8 +621,8 @@ |
| 619 | 621 | public function getNameserver(string $domain, array $query = []): Result {
|
| 620 | 622 | if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
|
| 621 | 623 | $cacheName = "listnameserver-{$domain}";
|
| 622 | | - $cache = $this->getCache($cacheName);
|
| 623 | | - if ($this->isValidLifespan($cache)) return Result::Success('', $cache);
|
| 624 | + $cache = $this->cache->get($cacheName);
|
| 625 | + if ($this->cache->validate($cache)) return Result::Success('', $cache);
|
| 624 | 626 |
|
| 625 | 627 | if (empty($query)) $query = [ 'limit' => 100, 'offset' => 0, 'order_by.name' => 'asc' ];
|
| 626 | 628 | foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
|
| | @@ -629,7 +631,7 @@ |
| 629 | 631 | $curl = $this->setupCurl($uri);
|
| 630 | 632 | $res = $this->curlResult($curl);
|
| 631 | 633 | if (isset($res->data['data'])) {
|
| 632 | | - $this->setCache($cacheName, $res->data);
|
| 634 | + $this->cache->set($cacheName, $res->data);
|
| 633 | 635 | return Result::Success('', $res->data);
|
| 634 | 636 | }
|
| 635 | 637 |
|
| | @@ -651,8 +653,8 @@ |
| 651 | 653 | $curl = $this->setupCurl($uri, 'PUT', $payload);
|
| 652 | 654 | $res = $this->curlResult($curl);
|
| 653 | 655 | if (isset($res->data['data'])) {
|
| 654 | | - $this->murderCache('listnameservers');
|
| 655 | | - $this->murderCache("listnameserver-{$domain}");
|
| 656 | + $this->cache->murder('listnameservers');
|
| 657 | + $this->cache->murder("listnameserver-{$domain}");
|
| 656 | 658 | if ($res->data['data']['success']) return Result::Success('ネームサーバーの更新に成功。', $res->data);
|
| 657 | 659 | }
|
| 658 | 660 |
|
| | @@ -673,8 +675,8 @@ |
| 673 | 675 | $curl = $this->setupCurl($uri, 'DELETE');
|
| 674 | 676 | $res = $this->curlResult($curl);
|
| 675 | 677 | if (isset($res->data['data'])) {
|
| 676 | | - $this->murderCache('listnameservers');
|
| 677 | | - $this->murderCache("listnameserver-{$domain}");
|
| 678 | + $this->cache->murder('listnameservers');
|
| 679 | + $this->cache->murder("listnameserver-{$domain}");
|
| 678 | 680 | if ($res->data['data']['success']) return Result::Success('ネームサーバーの削除に成功。', $res->data);
|
| 679 | 681 | }
|
| 680 | 682 |
|
| | @@ -693,8 +695,8 @@ |
| 693 | 695 | public function listNsGroups(array $query = []): Result {
|
| 694 | 696 | if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
|
| 695 | 697 | $cacheName = 'listnsgroups';
|
| 696 | | - $cache = $this->getCache($cacheName);
|
| 697 | | - if ($this->isValidLifespan($cache, $query)) return Result::Success('', $cache);
|
| 698 | + $cache = $this->cache->get($cacheName);
|
| 699 | + if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
|
| 698 | 700 |
|
| 699 | 701 | if (empty($query)) $query = [ 'limit' => 25, 'offset' => 0, 'order_by.name' => 'asc' ];
|
| 700 | 702 | foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
|
| | @@ -703,7 +705,7 @@ |
| 703 | 705 | $curl = $this->setupCurl($uri);
|
| 704 | 706 | $res = $this->curlResult($curl);
|
| 705 | 707 | if (isset($res->data['data'])) {
|
| 706 | | - $this->setCache($cacheName, $res->data);
|
| 708 | + $this->cache->set($cacheName, $res->data);
|
| 707 | 709 | return Result::Success('', $res->data);
|
| 708 | 710 | }
|
| 709 | 711 |
|
| | @@ -724,7 +726,7 @@ |
| 724 | 726 | $curl = $this->setupCurl($uri, 'POST', $payload);
|
| 725 | 727 | $res = $this->curlResult($curl);
|
| 726 | 728 | if (isset($res->data['data'])) {
|
| 727 | | - $this->murderCache('listnsgroups');
|
| 729 | + $this->cache->murder('listnsgroups');
|
| 728 | 730 | return Result::Success('NSグループの追加に成功。', $res->data);
|
| 729 | 731 | }
|
| 730 | 732 |
|
| | @@ -742,8 +744,8 @@ |
| 742 | 744 | public function getNsGroup(string $nsGroup, array $query = []): Result {
|
| 743 | 745 | if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
|
| 744 | 746 | $cacheName = "listnsgroup-{$nsGroup}";
|
| 745 | | - $cache = $this->getCache($cacheName);
|
| 746 | | - if ($this->isValidLifespan($cache)) return Result::Success('', $cache);
|
| 747 | + $cache = $this->cache->get($cacheName);
|
| 748 | + if ($this->cache->validate($cache)) return Result::Success('', $cache);
|
| 747 | 749 |
|
| 748 | 750 | if (empty($query)) $query = [ 'limit' => 100, 'offset' => 0, 'order_by.name' => 'asc' ];
|
| 749 | 751 | foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
|
| | @@ -752,7 +754,7 @@ |
| 752 | 754 | $curl = $this->setupCurl($uri);
|
| 753 | 755 | $res = $this->curlResult($curl);
|
| 754 | 756 | if (isset($res->data['data'])) {
|
| 755 | | - $this->setCache($cacheName, $res->data);
|
| 757 | + $this->cache->set($cacheName, $res->data);
|
| 756 | 758 | return Result::Success('', $res->data);
|
| 757 | 759 | }
|
| 758 | 760 |
|
| | @@ -774,8 +776,8 @@ |
| 774 | 776 | $curl = $this->setupCurl($uri, 'PUT', $payload);
|
| 775 | 777 | $res = $this->curlResult($curl);
|
| 776 | 778 | if (isset($res->data['data'])) {
|
| 777 | | - $this->murderCache('listnsgroups');
|
| 778 | | - $this->murderCache("listnsgroup-{$nsGroup}");
|
| 779 | + $this->cache->murder('listnsgroups');
|
| 780 | + $this->cache->murder("listnsgroup-{$nsGroup}");
|
| 779 | 781 | if ($res->data['data']['success']) return Result::Success('NSグループの更新に成功。', $res->data);
|
| 780 | 782 | }
|
| 781 | 783 |
|
| | @@ -796,8 +798,8 @@ |
| 796 | 798 | $curl = $this->setupCurl($uri, 'DELETE');
|
| 797 | 799 | $res = $this->curlResult($curl);
|
| 798 | 800 | if (isset($res->data['data'])) {
|
| 799 | | - $this->murderCache('listnsgroups');
|
| 800 | | - $this->murderCache("listnsgroup-{$nsGroup}");
|
| 801 | + $this->cache->murder('listnsgroups');
|
| 802 | + $this->cache->murder("listnsgroup-{$nsGroup}");
|
| 801 | 803 | if ($res->data['data']['success']) return Result::Success('NSグループの削除に成功。', $res->data);
|
| 802 | 804 | }
|
| 803 | 805 |
|
| | @@ -816,8 +818,8 @@ |
| 816 | 818 | public function listDnsTemplate(array $query = []): Result {
|
| 817 | 819 | if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
|
| 818 | 820 | $cacheName = 'listdnstemplates';
|
| 819 | | - $cache = $this->getCache($cacheName);
|
| 820 | | - if ($this->isValidLifespan($cache, $query)) return Result::Success('', $cache);
|
| 821 | + $cache = $this->cache->get($cacheName);
|
| 822 | + if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
|
| 821 | 823 |
|
| 822 | 824 | foreach ($query as $k => $v) { if (is_bool($v)) $query[$k] = $v ? 'true' : 'false'; }
|
| 823 | 825 | $uri = '/dns/templates?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
|
| | @@ -825,7 +827,7 @@ |
| 825 | 827 | $res = $this->curlResult($curl);
|
| 826 | 828 | if (isset($res->data['data'])) {
|
| 827 | 829 | $res->data['query'] = $query;
|
| 828 | | - $this->setCache($cacheName, $res->data);
|
| 830 | + $this->cache->set($cacheName, $res->data);
|
| 829 | 831 | return Result::Success('', $res->data);
|
| 830 | 832 | }
|
| 831 | 833 |
|
| | @@ -846,7 +848,7 @@ |
| 846 | 848 | $curl = $this->setupCurl($uri, 'POST', $payload);
|
| 847 | 849 | $res = $this->curlResult($curl);
|
| 848 | 850 | if (isset($res->data['data'])) {
|
| 849 | | - $this->murderCache('listdnstemplates');
|
| 851 | + $this->cache->murder('listdnstemplates');
|
| 850 | 852 | return Result::Success('DNSテンプレートの追加に成功。', $res->data);
|
| 851 | 853 | }
|
| 852 | 854 |
|
| | @@ -863,14 +865,14 @@ |
| 863 | 865 | public function getDnsTemplate(int $id): Result {
|
| 864 | 866 | if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
|
| 865 | 867 | $cacheName = "getdnstemplate-{$id}";
|
| 866 | | - $cache = $this->getCache($cacheName);
|
| 867 | | - if ($this->isValidLifespan($cache, $query)) return Result::Success('', $cache);
|
| 868 | + $cache = $this->cache->get($cacheName);
|
| 869 | + if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
|
| 868 | 870 |
|
| 869 | 871 | $uri = "/dns/templates/{$id}";
|
| 870 | 872 | $curl = $this->setupCurl($uri);
|
| 871 | 873 | $res = $this->curlResult($curl);
|
| 872 | 874 | if (isset($res->data['data'])) {
|
| 873 | | - $this->setCache($cacheName, $res->data);
|
| 875 | + $this->cache->set($cacheName, $res->data);
|
| 874 | 876 | return Result::Success('', $res->data);
|
| 875 | 877 | }
|
| 876 | 878 |
|
| | @@ -891,8 +893,8 @@ |
| 891 | 893 | $curl = $this->setupCurl($uri, 'DELETE');
|
| 892 | 894 | $res = $this->curlResult($curl);
|
| 893 | 895 | if (isset($res->data['data'])) {
|
| 894 | | - $this->murderCache('listdnstemplates');
|
| 895 | | - $this->murderCache("getdnstemplate-{$id}");
|
| 896 | + $this->cache->murder('listdnstemplates');
|
| 897 | + $this->cache->murder("getdnstemplate-{$id}");
|
| 896 | 898 | if ($res->data['data']['success']) return Result::Success('DNSテンプレートの削除に成功。', $res->data);
|
| 897 | 899 | }
|
| 898 | 900 |
|
| | @@ -910,8 +912,8 @@ |
| 910 | 912 | public function listDnsZones(array $query = []): Result {
|
| 911 | 913 | if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
|
| 912 | 914 | $cacheName = 'listdnszones';
|
| 913 | | - $cache = $this->getCache($cacheName);
|
| 914 | | - if ($this->isValidLifespan($cache, $query)) return Result::Success('', $cache);
|
| 915 | + $cache = $this->cache->get($cacheName);
|
| 916 | + if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
|
| 915 | 917 |
|
| 916 | 918 | if (empty($query)) $query = [ 'limit' => 25, 'offset' => 0, 'order_by.name' => 'asc' ];
|
| 917 | 919 | foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
|
| | @@ -920,7 +922,7 @@ |
| 920 | 922 | $curl = $this->setupCurl($uri);
|
| 921 | 923 | $res = $this->curlResult($curl);
|
| 922 | 924 | if (isset($res->data['data'])) {
|
| 923 | | - $this->setCache($cacheName, $res->data);
|
| 925 | + $this->cache->set($cacheName, $res->data);
|
| 924 | 926 | return Result::Success('', $res->data);
|
| 925 | 927 | }
|
| 926 | 928 |
|
| | @@ -941,7 +943,7 @@ |
| 941 | 943 | $curl = $this->setupCurl($uri, 'POST', $payload);
|
| 942 | 944 | $res = $this->curlResult($curl);
|
| 943 | 945 | if (isset($res->data['data'])) {
|
| 944 | | - $this->murderCache('listdnszones');
|
| 946 | + $this->cache->murder('listdnszones');
|
| 945 | 947 | return Result::Success('DNSゾーンの追加に成功。', $res->data);
|
| 946 | 948 | }
|
| 947 | 949 |
|
| | @@ -958,8 +960,8 @@ |
| 958 | 960 | public function getDnsZone(string $domain, array $query = []): Result {
|
| 959 | 961 | if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
|
| 960 | 962 | $cacheName = "getdnszone-{$domain}";
|
| 961 | | - $cache = $this->getCache($cacheName);
|
| 962 | | - if ($this->isValidLifespan($cache)) return Result::Success('', $cache);
|
| 963 | + $cache = $this->cache->get($cacheName);
|
| 964 | + if ($this->cache->validate($cache)) return Result::Success('', $cache);
|
| 963 | 965 |
|
| 964 | 966 | if (empty($query)) $query = [ 'limit' => 100, 'offset' => 0, 'order_by.name' => 'asc' ];
|
| 965 | 967 | foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
|
| | @@ -968,7 +970,7 @@ |
| 968 | 970 | $curl = $this->setupCurl($uri);
|
| 969 | 971 | $res = $this->curlResult($curl);
|
| 970 | 972 | if (isset($res->data['data'])) {
|
| 971 | | - $this->setCache($cacheName, $res->data);
|
| 973 | + $this->cache->set($cacheName, $res->data);
|
| 972 | 974 | return Result::Success('', $res->data);
|
| 973 | 975 | }
|
| 974 | 976 |
|
| | @@ -990,8 +992,8 @@ |
| 990 | 992 | $curl = $this->setupCurl($uri, 'PUT', $payload);
|
| 991 | 993 | $res = $this->curlResult($curl);
|
| 992 | 994 | if (isset($res->data['data'])) {
|
| 993 | | - $this->murderCache('listdnszones');
|
| 994 | | - $this->murderCache("getdnszone-{$domain}");
|
| 995 | + $this->cache->murder('listdnszones');
|
| 996 | + $this->cache->murder("getdnszone-{$domain}");
|
| 995 | 997 | if ($res->data['data']['success']) return Result::Success('DNSゾーンの更新に成功。', $res->data);
|
| 996 | 998 | }
|
| 997 | 999 |
|
| | @@ -1012,8 +1014,8 @@ |
| 1012 | 1014 | $curl = $this->setupCurl($uri, 'DELETE');
|
| 1013 | 1015 | $res = $this->curlResult($curl);
|
| 1014 | 1016 | if (isset($res->data['data'])) {
|
| 1015 | | - $this->murderCache('listdnszones');
|
| 1016 | | - $this->murderCache("getdnszone-{$domain}");
|
| 1017 | + $this->cache->murder('listdnszones');
|
| 1018 | + $this->cache->murder("getdnszone-{$domain}");
|
| 1017 | 1019 | if ($res->data['data']['success']) return Result::Success('DNSゾーンの削除に成功。', $res->data);
|
| 1018 | 1020 | }
|
| 1019 | 1021 |
|
| | @@ -1031,13 +1033,13 @@ |
| 1031 | 1033 | public function listZoneRecords(string $domain): Result {
|
| 1032 | 1034 | if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
|
| 1033 | 1035 | $cacheName = "getzonerecords-{$domain}";
|
| 1034 | | - $cache = $this->getCache($cacheName);
|
| 1035 | | - if ($this->isValidLifespan($cache)) return Result::Success('', $cache);
|
| 1036 | + $cache = $this->cache->get($cacheName);
|
| 1037 | + if ($this->cache->validate($cache)) return Result::Success('', $cache);
|
| 1036 | 1038 |
|
| 1037 | 1039 | $curl = $this->setupCurl("/dns/zones/{$domain}/records");
|
| 1038 | 1040 | $res = $this->curlResult($curl);
|
| 1039 | 1041 | if (isset($res->data['data'])) {
|
| 1040 | | - $this->setCache($cacheName, $res->data);
|
| 1042 | + $this->cache->set($cacheName, $res->data);
|
| 1041 | 1043 | return Result::Success('', $res->data);
|
| 1042 | 1044 | }
|
| 1043 | 1045 |
|
| | @@ -1060,8 +1062,8 @@ |
| 1060 | 1062 | public function listEmails(array $query = []): Result {
|
| 1061 | 1063 | if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
|
| 1062 | 1064 | $cacheName = 'listemails';
|
| 1063 | | - $cache = $this->getCache($cacheName);
|
| 1064 | | - if ($this->isValidLifespan($cache, $query)) return Result::Success('', $cache);
|
| 1065 | + $cache = $this->cache->get($cacheName);
|
| 1066 | + if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
|
| 1065 | 1067 |
|
| 1066 | 1068 | foreach ($query as $k => $v) { if (is_bool($v)) $query[$k] = $v ? 'true' : 'false'; }
|
| 1067 | 1069 | $uri = '/emails?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
|
| | @@ -1069,7 +1071,7 @@ |
| 1069 | 1071 | $res = $this->curlResult($curl);
|
| 1070 | 1072 | if (isset($res->data['data'])) {
|
| 1071 | 1073 | $res->data['query'] = $query;
|
| 1072 | | - $this->setCache($cacheName, $res->data);
|
| 1074 | + $this->cache->set($cacheName, $res->data);
|
| 1073 | 1075 | return Result::Success('', $res->data);
|
| 1074 | 1076 | }
|
| 1075 | 1077 |
|
| | @@ -1090,7 +1092,7 @@ |
| 1090 | 1092 | $curl = $this->setupCurl($uri, 'POST', $payload);
|
| 1091 | 1093 | $res = $this->curlResult($curl);
|
| 1092 | 1094 | if (isset($res->data['data'])) {
|
| 1093 | | - $this->murderCache('listemails');
|
| 1095 | + $this->cache->murder('listemails');
|
| 1094 | 1096 | return Result::Success('メールテンプレートの追加に成功。', $res->data);
|
| 1095 | 1097 | }
|
| 1096 | 1098 |
|
| | @@ -1112,7 +1114,7 @@ |
| 1112 | 1114 | $curl = $this->setupCurl($uri, 'PUT', $payload);
|
| 1113 | 1115 | $res = $this->curlResult($curl);
|
| 1114 | 1116 | if (isset($res->data['data'])) {
|
| 1115 | | - $this->murderCache('listemails');
|
| 1117 | + $this->cache->murder('listemails');
|
| 1116 | 1118 | if ($res->data['data']['success']) return Result::Success('メールテンプレートの更新に成功。', $res->data);
|
| 1117 | 1119 | }
|
| 1118 | 1120 |
|
| | @@ -1133,7 +1135,7 @@ |
| 1133 | 1135 | $curl = $this->setupCurl($uri, 'DELETE');
|
| 1134 | 1136 | $res = $this->curlResult($curl);
|
| 1135 | 1137 | if (isset($res->data['data'])) {
|
| 1136 | | - $this->murderCache('listemails');
|
| 1138 | + $this->cache->murder('listemails');
|
| 1137 | 1139 | if ($res->data['data']['success']) return Result::Success('メールテンプレートの削除に成功。', $res->data);
|
| 1138 | 1140 | }
|
| 1139 | 1141 |
|
| | @@ -1155,8 +1157,8 @@ |
| 1155 | 1157 | public function listContacts(array $query = []): Result {
|
| 1156 | 1158 | if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
|
| 1157 | 1159 | $cacheName = 'listcontacts';
|
| 1158 | | - $cache = $this->getCache($cacheName);
|
| 1159 | | - if ($this->isValidLifespan($cache, $query)) return Result::Success('', $cache);
|
| 1160 | + $cache = $this->cache->get($cacheName);
|
| 1161 | + if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
|
| 1160 | 1162 |
|
| 1161 | 1163 | foreach ($query as $k => $v) { if (is_bool($v)) $query[$k] = $v ? 'true' : 'false'; }
|
| 1162 | 1164 | $uri = '/contacts?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
|
| | @@ -1164,7 +1166,7 @@ |
| 1164 | 1166 | $res = $this->curlResult($curl);
|
| 1165 | 1167 | if (isset($res->data['data'])) {
|
| 1166 | 1168 | $res->data['query'] = $query;
|
| 1167 | | - $this->setCache($cacheName, $res->data);
|
| 1169 | + $this->cache->set($cacheName, $res->data);
|
| 1168 | 1170 | return Result::Success('', $res->data);
|
| 1169 | 1171 | }
|
| 1170 | 1172 |
|
| | @@ -1184,7 +1186,7 @@ |
| 1184 | 1186 | $curl = $this->setupCurl($uri, 'POST', $payload);
|
| 1185 | 1187 | $res = $this->curlResult($curl);
|
| 1186 | 1188 | if (isset($res)) {
|
| 1187 | | - $this->murderCache('listcontacts');
|
| 1189 | + $this->cache->murder('listcontacts');
|
| 1188 | 1190 | return Result::Success('', $res->data);
|
| 1189 | 1191 | }
|
| 1190 | 1192 |
|
| | @@ -1201,8 +1203,8 @@ |
| 1201 | 1203 | public function getContact(int $id, bool $withAdditionalData = false): Result {
|
| 1202 | 1204 | if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
|
| 1203 | 1205 | $cacheName = "getcontact-{$id}";
|
| 1204 | | - $cache = $this->getCache($cacheName);
|
| 1205 | | - if ($this->isValidLifespan($cache, $id, 'id')) return Result::Success('', $cache);
|
| 1206 | + $cache = $this->cache->get($cacheName);
|
| 1207 | + if ($this->cache->validate($cache, $id, 'id')) return Result::Success('', $cache);
|
| 1206 | 1208 |
|
| 1207 | 1209 | $query = [ 'with_additional_data' => $withAdditionalData ? 'true' : 'false' ];
|
| 1208 | 1210 | $uri = "/contacts/{$id}?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
|
| | @@ -1211,7 +1213,7 @@ |
| 1211 | 1213 | $res = $this->curlResult($curl);
|
| 1212 | 1214 | if (isset($res->data['data'])) {
|
| 1213 | 1215 | $res->data['id'] = $id;
|
| 1214 | | - $this->setCache($cacheName, $res->data);
|
| 1216 | + $this->cache->set($cacheName, $res->data);
|
| 1215 | 1217 | return Result::Success('', $res->data);
|
| 1216 | 1218 | }
|
| 1217 | 1219 |
|
| | @@ -1233,8 +1235,8 @@ |
| 1233 | 1235 | $curl = $this->setupCurl($uri, 'PUT', $payload);
|
| 1234 | 1236 | $res = $this->curlResult($curl);
|
| 1235 | 1237 | if (isset($res->data['data'])) {
|
| 1236 | | - $this->murderCache("getcontact-{$id}");
|
| 1237 | | - $this->murderCache('listcontacts');
|
| 1238 | + $this->cache->murder("getcontact-{$id}");
|
| 1239 | + $this->cache->murder('listcontacts');
|
| 1238 | 1240 | if ($res->data['data']['success']) return Result::Success('連絡先の更新に成功。', $res->data);
|
| 1239 | 1241 | }
|
| 1240 | 1242 |
|
| | @@ -1254,8 +1256,8 @@ |
| 1254 | 1256 | $curl = $this->setupCurl($uri, 'DELETE');
|
| 1255 | 1257 | $res = $this->curlResult($curl);
|
| 1256 | 1258 | if (isset($res->data['data'])) {
|
| 1257 | | - $this->murderCache("getcontact-{$id}");
|
| 1258 | | - $this->murderCache('listcontacts');
|
| 1259 | + $this->cache->murder("getcontact-{$id}");
|
| 1260 | + $this->cache->murder('listcontacts');
|
| 1259 | 1261 | if ($res->data['data']['success']) return Result::Success('連絡先の削除に成功。');
|
| 1260 | 1262 | }
|
| 1261 | 1263 |
|
| | @@ -1273,8 +1275,8 @@ |
| 1273 | 1275 | public function listCustomers(array $query = []): Result {
|
| 1274 | 1276 | if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
|
| 1275 | 1277 | $cacheName = 'listcustomers';
|
| 1276 | | - $cache = $this->getCache($cacheName);
|
| 1277 | | - if ($this->isValidLifespan($cache, $query)) return Result::Success('', $cache);
|
| 1278 | + $cache = $this->cache->get($cacheName);
|
| 1279 | + if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
|
| 1278 | 1280 |
|
| 1279 | 1281 | foreach ($query as $k => $v) { if (is_bool($v)) $query[$k] = $v ? 'true' : 'false'; }
|
| 1280 | 1282 | $uri = '/customers?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
|
| | @@ -1282,7 +1284,7 @@ |
| 1282 | 1284 | $res = $this->curlResult($curl);
|
| 1283 | 1285 | if (isset($res->data['data'])) {
|
| 1284 | 1286 | $res->data['query'] = $query;
|
| 1285 | | - $this->setCache($cacheName, $res->data);
|
| 1287 | + $this->cache->set($cacheName, $res->data);
|
| 1286 | 1288 | return Result::Success('', $res->data);
|
| 1287 | 1289 | }
|
| 1288 | 1290 |
|
| | @@ -1302,7 +1304,7 @@ |
| 1302 | 1304 | $curl = $this->setupCurl($uri, 'POST', $payload);
|
| 1303 | 1305 | $res = $this->curlResult($curl);
|
| 1304 | 1306 | if (isset($res)) {
|
| 1305 | | - $this->murderCache('listcustomers');
|
| 1307 | + $this->cache->murder('listcustomers');
|
| 1306 | 1308 | return Result::Success('', $res->data);
|
| 1307 | 1309 | }
|
| 1308 | 1310 |
|
| | @@ -1319,8 +1321,8 @@ |
| 1319 | 1321 | public function getCustomer(string $handle, bool $withAdditionalData = false): Result {
|
| 1320 | 1322 | if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
|
| 1321 | 1323 | $cacheName = "getcustomer-{$handle}";
|
| 1322 | | - $cache = $this->getCache($cacheName);
|
| 1323 | | - if ($this->isValidLifespan($cache, $handle, 'handle')) return Result::Success('', $cache);
|
| 1324 | + $cache = $this->cache->get($cacheName);
|
| 1325 | + if ($this->cache->validate($cache, $handle, 'handle')) return Result::Success('', $cache);
|
| 1324 | 1326 |
|
| 1325 | 1327 | $query = [ 'with_additional_data' => $withAdditionalData ? 'true' : 'false' ];
|
| 1326 | 1328 | $uri = "/customers/{$handle}?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
|
| | @@ -1329,7 +1331,7 @@ |
| 1329 | 1331 | $res = $this->curlResult($curl);
|
| 1330 | 1332 | if (isset($res->data['data'])) {
|
| 1331 | 1333 | $res->data['handle'] = $handle;
|
| 1332 | | - $this->setCache($cacheName, $res->data);
|
| 1334 | + $this->cache->set($cacheName, $res->data);
|
| 1333 | 1335 | return Result::Success('', $res->data);
|
| 1334 | 1336 | }
|
| 1335 | 1337 |
|
| | @@ -1351,7 +1353,8 @@ |
| 1351 | 1353 | $curl = $this->setupCurl($uri, 'PUT', $payload);
|
| 1352 | 1354 | $res = $this->curlResult($curl);
|
| 1353 | 1355 | if (isset($res->data['data'])) {
|
| 1354 | | - $this->murderCache('listcustomers');
|
| 1356 | + $this->cache->murder('listcustomers');
|
| 1357 | + $this->cache->murder("getcustomer-{$handle}");
|
| 1355 | 1358 | if ($res->data['data']['success']) return Result::Success('顧客様の更新に成功。', $res->data);
|
| 1356 | 1359 | }
|
| 1357 | 1360 |
|
| | @@ -1371,7 +1374,8 @@ |
| 1371 | 1374 | $curl = $this->setupCurl($uri, 'DELETE');
|
| 1372 | 1375 | $res = $this->curlResult($curl);
|
| 1373 | 1376 | if (isset($res->data['data'])) {
|
| 1374 | | - $this->murderCache('listcustomers');
|
| 1377 | + $this->cache->murder('listcustomers');
|
| 1378 | + $this->cache->murder("getcustomer-{$handle}");
|
| 1375 | 1379 | if ($res->data['data']['success']) return Result::Success('顧客様の削除に成功。');
|
| 1376 | 1380 | }
|
| 1377 | 1381 |
|
| | @@ -1390,8 +1394,8 @@ |
| 1390 | 1394 | public function listEmailVerifications(array $query = []): Result {
|
| 1391 | 1395 | if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
|
| 1392 | 1396 | $cacheName = 'listemailverifications';
|
| 1393 | | - $cache = $this->getCache($cacheName);
|
| 1394 | | - if ($this->isValidLifespan($cache, $query)) return Result::Success('', $cache);
|
| 1397 | + $cache = $this->cache->get($cacheName);
|
| 1398 | + if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
|
| 1395 | 1399 |
|
| 1396 | 1400 | foreach ($query as $k => $v) { if (is_bool($v)) $query[$k] = $v ? 'true' : 'false'; }
|
| 1397 | 1401 | $uri = '/customers/verifications/emails/domains?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
|
| | @@ -1399,7 +1403,7 @@ |
| 1399 | 1403 | $res = $this->curlResult($curl);
|
| 1400 | 1404 | if (isset($res->data['data'])) {
|
| 1401 | 1405 | $res->data['query'] = $query;
|
| 1402 | | - $this->setCache($cacheName, $res->data);
|
| 1406 | + $this->cache->set($cacheName, $res->data);
|
| 1403 | 1407 | return Result::Success('', $res->data);
|
| 1404 | 1408 | }
|
| 1405 | 1409 |
|
| | @@ -1420,7 +1424,7 @@ |
| 1420 | 1424 | $curl = $this->setupCurl($uri, 'POST', ['email' => $email, 'language' => $language, 'tag' => $tag]);
|
| 1421 | 1425 | $res = $this->curlResult($curl);
|
| 1422 | 1426 | if (isset($res->data['data'])) {
|
| 1423 | | - $this->murderCache('listemailverifications');
|
| 1427 | + $this->cache->murder('listemailverifications');
|
| 1424 | 1428 | return Result::Success('メール認証の再起動に成功。', $res->data);
|
| 1425 | 1429 | }
|
| 1426 | 1430 |
|
| | @@ -1444,7 +1448,7 @@ |
| 1444 | 1448 | $curl = $this->setupCurl($uri, 'POST', ['email' => $email, 'handle' => $handle, 'language' => $language, 'tag' => $tag]);
|
| 1445 | 1449 | $res = $this->curlResult($curl);
|
| 1446 | 1450 | if (isset($res->data['data'])) {
|
| 1447 | | - $this->murderCache('listemailverifications');
|
| 1451 | + $this->cache->murder('listemailverifications');
|
| 1448 | 1452 | return Result::Success('メール認証の起動に成功。', $res->data);
|
| 1449 | 1453 | }
|
| 1450 | 1454 |
|
| | @@ -1463,8 +1467,8 @@ |
| 1463 | 1467 | public function getReseller(array $query = []): Result {
|
| 1464 | 1468 | if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
|
| 1465 | 1469 | $cacheName = 'getreseller';
|
| 1466 | | - $cache = $this->getCache($cacheName);
|
| 1467 | | - if ($this->isValidLifespan($cache, $query)) return Result::Success('', $cache);
|
| 1470 | + $cache = $this->cache->get($cacheName);
|
| 1471 | + if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
|
| 1468 | 1472 |
|
| 1469 | 1473 | foreach ($query as $k => $v) { if (is_bool($v)) $query[$k] = $v ? 'true' : 'false'; }
|
| 1470 | 1474 | $uri = '/resellers?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
|
| | @@ -1472,7 +1476,7 @@ |
| 1472 | 1476 | $res = $this->curlResult($curl);
|
| 1473 | 1477 | if (isset($res->data['data'])) {
|
| 1474 | 1478 | $res->data['query'] = $query;
|
| 1475 | | - $this->setCache($cacheName, $res->data);
|
| 1479 | + $this->cache->set($cacheName, $res->data);
|
| 1476 | 1480 | return Result::Success('', $res->data);
|
| 1477 | 1481 | }
|
| 1478 | 1482 |
|
| | @@ -1494,7 +1498,7 @@ |
| 1494 | 1498 | $curl = $this->setupCurl($uri, 'PUT', $payload);
|
| 1495 | 1499 | $res = $this->curlResult($curl);
|
| 1496 | 1500 | if (isset($res->data['data'])) {
|
| 1497 | | - $this->murderCache('getreseller');
|
| 1501 | + $this->cache->murder('getreseller');
|
| 1498 | 1502 | if ($res->data['data']['success']) return Result::Success('リセラーの更新に成功。', $res->data);
|
| 1499 | 1503 | }
|
| 1500 | 1504 |
|
| | @@ -1512,15 +1516,15 @@ |
| 1512 | 1516 | public function listSettings(): Result {
|
| 1513 | 1517 | if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
|
| 1514 | 1518 | $cacheName = 'listsettings';
|
| 1515 | | - $cache = $this->getCache($cacheName);
|
| 1516 | | - if ($this->isValidLifespan($cache, $query)) return Result::Success('', $cache);
|
| 1519 | + $cache = $this->cache->get($cacheName);
|
| 1520 | + if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
|
| 1517 | 1521 |
|
| 1518 | 1522 | $uri = '/resellers/settings';
|
| 1519 | 1523 | $curl = $this->setupCurl($uri);
|
| 1520 | 1524 | $res = $this->curlResult($curl);
|
| 1521 | 1525 | if (isset($res->data['data'])) {
|
| 1522 | 1526 | $res->data['query'] = $query;
|
| 1523 | | - $this->setCache($cacheName, $res->data);
|
| 1527 | + $this->cache->set($cacheName, $res->data);
|
| 1524 | 1528 | return Result::Success('', $res->data);
|
| 1525 | 1529 | }
|
| 1526 | 1530 |
|
| | @@ -1538,15 +1542,15 @@ |
| 1538 | 1542 | public function listStatistics(array $query = []): Result {
|
| 1539 | 1543 | if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
|
| 1540 | 1544 | $cacheName = 'liststatistics';
|
| 1541 | | - $cache = $this->getCache($cacheName);
|
| 1542 | | - if ($this->isValidLifespan($cache, $query)) return Result::Success('', $cache);
|
| 1545 | + $cache = $this->cache->get($cacheName);
|
| 1546 | + if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
|
| 1543 | 1547 |
|
| 1544 | 1548 | $uri = '/resellers/statistics';
|
| 1545 | 1549 | $curl = $this->setupCurl($uri);
|
| 1546 | 1550 | $res = $this->curlResult($curl);
|
| 1547 | 1551 | if (isset($res->data['data'])) {
|
| 1548 | 1552 | $res->data['query'] = $query;
|
| 1549 | | - $this->setCache($cacheName, $res->data);
|
| 1553 | + $this->cache->set($cacheName, $res->data);
|
| 1550 | 1554 | return Result::Success('', $res->data);
|
| 1551 | 1555 | }
|
| 1552 | 1556 |
|
| | @@ -1565,8 +1569,8 @@ |
| 1565 | 1569 | public function listTags(array $query = []): Result {
|
| 1566 | 1570 | if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
|
| 1567 | 1571 | $cacheName = 'listtags';
|
| 1568 | | - $cache = $this->getCache($cacheName);
|
| 1569 | | - if ($this->isValidLifespan($cache, $query)) return Result::Success('', $cache);
|
| 1572 | + $cache = $this->cache->get($cacheName);
|
| 1573 | + if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
|
| 1570 | 1574 |
|
| 1571 | 1575 | foreach ($query as $k => $v) { if (is_bool($v)) $query[$k] = $v ? 'true' : 'false'; }
|
| 1572 | 1576 | $uri = '/tags?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
|
| | @@ -1574,7 +1578,7 @@ |
| 1574 | 1578 | $res = $this->curlResult($curl);
|
| 1575 | 1579 | if (isset($res->data['data'])) {
|
| 1576 | 1580 | $res->data['query'] = $query;
|
| 1577 | | - $this->setCache($cacheName, $res->data);
|
| 1581 | + $this->cache->set($cacheName, $res->data);
|
| 1578 | 1582 | return Result::Success('', $res->data);
|
| 1579 | 1583 | }
|
| 1580 | 1584 |
|
| | @@ -1595,7 +1599,7 @@ |
| 1595 | 1599 | $curl = $this->setupCurl($uri, 'POST', $payload);
|
| 1596 | 1600 | $res = $this->curlResult($curl);
|
| 1597 | 1601 | if (isset($res->data['data'])) {
|
| 1598 | | - $this->murderCache('listtags');
|
| 1602 | + $this->cache->murder('listtags');
|
| 1599 | 1603 | return Result::Success('タグの追加に成功。', $res->data);
|
| 1600 | 1604 | }
|
| 1601 | 1605 |
|
| | @@ -1616,7 +1620,7 @@ |
| 1616 | 1620 | $curl = $this->setupCurl($uri, 'DELETE', $payload);
|
| 1617 | 1621 | $res = $this->curlResult($curl);
|
| 1618 | 1622 | if (isset($res->data['data'])) {
|
| 1619 | | - $this->murderCache('listtags');
|
| 1623 | + $this->cache->murder('listtags');
|
| 1620 | 1624 | if ($res->data['data']['success']) return Result::Success('タグの削除に成功。', $res->data);
|
| 1621 | 1625 | }
|
| 1622 | 1626 |
|
| | @@ -1641,7 +1645,7 @@ |
| 1641 | 1645 | $curl = $this->setupCurl($uri, 'POST', $payload);
|
| 1642 | 1646 | $res = $this->curlResult($curl);
|
| 1643 | 1647 | if (isset($res)) {
|
| 1644 | | - $this->murderCache('listdomains');
|
| 1648 | + $this->cache->murder('listdomains');
|
| 1645 | 1649 | return Result::Success('', $res->data);
|
| 1646 | 1650 | }
|
| 1647 | 1651 |
|
| | @@ -1659,8 +1663,8 @@ |
| 1659 | 1663 | public function getSeDomain(string $domain, array $query = []): Result {
|
| 1660 | 1664 | if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
|
| 1661 | 1665 | $cacheName = "getsedomain-{$domain}";
|
| 1662 | | - $cache = $this->getCache($cacheName);
|
| 1663 | | - if ($this->isValidLifespan($cache, $domain, 'domain')) return Result::Success('', $cache);
|
| 1666 | + $cache = $this->cache->get($cacheName);
|
| 1667 | + if ($this->cache->validate($cache, $domain, 'domain')) return Result::Success('', $cache);
|
| 1664 | 1668 |
|
| 1665 | 1669 | $uri = "/spam-expert/domains/{$domain}?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
|
| 1666 | 1670 | // kys($uri);
|
| | @@ -1668,7 +1672,7 @@ |
| 1668 | 1672 | $res = $this->curlResult($curl);
|
| 1669 | 1673 | if (isset($res->data['data'])) {
|
| 1670 | 1674 | $res->data['domain'] = $domain;
|
| 1671 | | - $this->setCache($cacheName, $res->data);
|
| 1675 | + $this->cache->set($cacheName, $res->data);
|
| 1672 | 1676 | return Result::Success('', $res->data);
|
| 1673 | 1677 | }
|
| 1674 | 1678 |
|
| | @@ -1690,8 +1694,8 @@ |
| 1690 | 1694 | $curl = $this->setupCurl($uri, 'PUT', $payload);
|
| 1691 | 1695 | $res = $this->curlResult($curl);
|
| 1692 | 1696 | if (isset($res->data['data'])) {
|
| 1693 | | - $this->murderCache('listdomains');
|
| 1694 | | - $this->murderCache("getsedomain-{$domain}");
|
| 1697 | + $this->cache->murder('listdomains');
|
| 1698 | + $this->cache->murder("getsedomain-{$domain}");
|
| 1695 | 1699 | if ($res->data['data']['success']) return Result::Success('SEDomainの更新に成功。', $res->data);
|
| 1696 | 1700 | }
|
| 1697 | 1701 |
|
| | @@ -1712,8 +1716,8 @@ |
| 1712 | 1716 | $curl = $this->setupCurl($uri, 'DELETE');
|
| 1713 | 1717 | $res = $this->curlResult($curl);
|
| 1714 | 1718 | if (isset($res->data['data'])) {
|
| 1715 | | - $this->murderCache('listdomains');
|
| 1716 | | - $this->murderCache("getsedomain-{$domain}");
|
| 1719 | + $this->cache->murder('listdomains');
|
| 1720 | + $this->cache->murder("getsedomain-{$domain}");
|
| 1717 | 1721 | if ($res->data['data']['success']) return Result::Success('SEDomainの削除に成功。');
|
| 1718 | 1722 | }
|
| 1719 | 1723 |
|
| | @@ -1734,8 +1738,8 @@ |
| 1734 | 1738 | public function listApproverEmails(array $query = []): Result {
|
| 1735 | 1739 | if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
|
| 1736 | 1740 | $cacheName = 'listapproveremails';
|
| 1737 | | - $cache = $this->getCache($cacheName);
|
| 1738 | | - if ($this->isValidLifespan($cache, $query)) return Result::Success('', $cache);
|
| 1741 | + $cache = $this->cache->get($cacheName);
|
| 1742 | + if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
|
| 1739 | 1743 |
|
| 1740 | 1744 | foreach ($query as $k => $v) { if (is_bool($v)) $query[$k] = $v ? 'true' : 'false'; }
|
| 1741 | 1745 | $uri = '/ssl/approver-emails?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
|
| | @@ -1743,7 +1747,7 @@ |
| 1743 | 1747 | $res = $this->curlResult($curl);
|
| 1744 | 1748 | if (isset($res->data['data'])) {
|
| 1745 | 1749 | $res->data['query'] = $query;
|
| 1746 | | - $this->setCache($cacheName, $res->data);
|
| 1750 | + $this->cache->set($cacheName, $res->data);
|
| 1747 | 1751 | return Result::Success('', $res->data);
|
| 1748 | 1752 | }
|
| 1749 | 1753 |
|
| | @@ -1811,7 +1815,7 @@ |
| 1811 | 1815 | $curl = $this->setupCurl($uri, 'PUT', ['id' => $id, 'approver_email' => $approverEmail]);
|
| 1812 | 1816 | $res = $this->curlResult($curl);
|
| 1813 | 1817 | if (isset($res)) {
|
| 1814 | | - $this->murderCache('listapproveremails');
|
| 1818 | + $this->cache->murder('listapproveremails');
|
| 1815 | 1819 | return Result::Success('', $res->data);
|
| 1816 | 1820 | }
|
| 1817 | 1821 |
|
| | @@ -1832,7 +1836,7 @@ |
| 1832 | 1836 | $curl = $this->setupCurl($uri, 'POST', ['id' => $id]);
|
| 1833 | 1837 | $res = $this->curlResult($curl);
|
| 1834 | 1838 | if (isset($res)) {
|
| 1835 | | - $this->murderCache('listapproveremails');
|
| 1839 | + $this->cache->murder('listapproveremails');
|
| 1836 | 1840 | return Result::Success('', $res->data);
|
| 1837 | 1841 | }
|
| 1838 | 1842 |
|
| | @@ -1873,8 +1877,8 @@ |
| 1873 | 1877 | public function listSslProducts(array $query = []): Result {
|
| 1874 | 1878 | if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
|
| 1875 | 1879 | $cacheName = 'listsslproducts';
|
| 1876 | | - $cache = $this->getCache($cacheName);
|
| 1877 | | - if ($this->isValidLifespan($cache, $query)) return Result::Success('', $cache);
|
| 1880 | + $cache = $this->cache->get($cacheName);
|
| 1881 | + if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
|
| 1878 | 1882 |
|
| 1879 | 1883 | foreach ($query as $k => $v) { if (is_bool($v)) $query[$k] = $v ? 'true' : 'false'; }
|
| 1880 | 1884 | $uri = '/ssl/products?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
|
| | @@ -1882,7 +1886,7 @@ |
| 1882 | 1886 | $res = $this->curlResult($curl);
|
| 1883 | 1887 | if (isset($res->data['data'])) {
|
| 1884 | 1888 | $res->data['query'] = $query;
|
| 1885 | | - $this->setCache($cacheName, $res->data);
|
| 1889 | + $this->cache->set($cacheName, $res->data);
|
| 1886 | 1890 | return Result::Success('', $res->data);
|
| 1887 | 1891 | }
|
| 1888 | 1892 |
|
| | @@ -1899,14 +1903,14 @@ |
| 1899 | 1903 | public function getSslProduct(int $id): Result {
|
| 1900 | 1904 | if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
|
| 1901 | 1905 | $cacheName = "getsslproduct-{$id}";
|
| 1902 | | - $cache = $this->getCache($cacheName);
|
| 1903 | | - if ($this->isValidLifespan($cache, $id, 'id')) return Result::Success('', $cache);
|
| 1906 | + $cache = $this->cache->get($cacheName);
|
| 1907 | + if ($this->cache->validate($cache, $id, 'id')) return Result::Success('', $cache);
|
| 1904 | 1908 | // kys($uri);
|
| 1905 | 1909 | $curl = $this->setupCurl($uri);
|
| 1906 | 1910 | $res = $this->curlResult($curl);
|
| 1907 | 1911 | if (isset($res->data['data'])) {
|
| 1908 | 1912 | $res->data['id'] = $id;
|
| 1909 | | - $this->setCache($cacheName, $res->data);
|
| 1913 | + $this->cache->set($cacheName, $res->data);
|
| 1910 | 1914 | return Result::Success('', $res->data);
|
| 1911 | 1915 | }
|
| 1912 | 1916 |
|
| | @@ -1967,76 +1971,5 @@ |
| 1967 | 1971 | assert_not_null($body, "返事ボディーは空です。");
|
| 1968 | 1972 |
|
| 1969 | 1973 | return Result::Success('', json_decode($body, true));
|
| 1970 | | - }
|
| 1971 | | -
|
| 1972 | | - /**
|
| 1973 | | - * キャッシュの作成
|
| 1974 | | - *
|
| 1975 | | - * @param string $type キャッシュ類(例:login、domainlist等)
|
| 1976 | | - * @param array $data 保存するデータ
|
| 1977 | | - * @return Result
|
| 1978 | | - */
|
| 1979 | | - private function setCache(string $type, array $data): Result {
|
| 1980 | | - if (!file_exists($this->dataDir)) {
|
| 1981 | | - if (!mkdir($this->dataDir, 0755))
|
| 1982 | | - return Result::Error('エラー:ユーザーのアイコンディレクトリの作成に失敗。');
|
| 1983 | | - }
|
| 1984 | | -
|
| 1985 | | - $data['lifespan'] = time();
|
| 1986 | | - $json = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
| 1987 | | - if (file_put_contents("{$this->dataDir}{$type}.json", $json) === false) return Result::Error('エラー:ユーザーデータの保存に失敗。');
|
| 1988 | | -
|
| 1989 | | - return Result::Success();
|
| 1990 | | - }
|
| 1991 | | -
|
| 1992 | | - /**
|
| 1993 | | - * キャッシュから受け取り
|
| 1994 | | - *
|
| 1995 | | - * @param string $type キャッシュ類(例:login、domainlist等)
|
| 1996 | | - * @return array
|
| 1997 | | - */
|
| 1998 | | - private function getCache(string $type): array {
|
| 1999 | | - if (!file_exists("{$this->dataDir}{$type}.json")) return [];
|
| 2000 | | -
|
| 2001 | | - $content = file_get_contents("{$this->dataDir}{$type}.json");
|
| 2002 | | - if ($content === false) return [];
|
| 2003 | | -
|
| 2004 | | - $data = json_decode($content, true);
|
| 2005 | | - if (json_last_error() !== JSON_ERROR_NONE || !is_array($data)) return [];
|
| 2006 | | -
|
| 2007 | | - if ($type === 'login') {
|
| 2008 | | - $this->token = $data['data']['token'];
|
| 2009 | | - $this->lastAuth = $data['last_auth'];
|
| 2010 | | - }
|
| 2011 | | -
|
| 2012 | | - return $data;
|
| 2013 | | - }
|
| 2014 | | -
|
| 2015 | | - /**
|
| 2016 | | - * キャッシュを破壊する
|
| 2017 | | - *
|
| 2018 | | - * @param string $name キャッシュのファイル名
|
| 2019 | | - * @return Result
|
| 2020 | | - */
|
| 2021 | | - private function murderCache(string $name): Result {
|
| 2022 | | - if (!file_exists("{$this->dataDir}{$name}.json")) return Result::Error('キャッシュファイルが存在しない。');
|
| 2023 | | - if (!unlink("{$this->dataDir}{$name}.json")) return Result::Error('キャッシュファイルの削除に失敗。');
|
| 2024 | | - return Result::Success();
|
| 2025 | | - }
|
| 2026 | | -
|
| 2027 | | - /**
|
| 2028 | | - * キャッシュ有効期限の確認
|
| 2029 | | - *
|
| 2030 | | - * @param array $cache
|
| 2031 | | - * @param mixed $data デフォルト=null
|
| 2032 | | - * @param string $dataPoint デフォルト=query
|
| 2033 | | - * @return bool
|
| 2034 | | - */
|
| 2035 | | - private function isValidLifespan(array $cache, mixed $data = null, string $dataPoint = 'query'): bool {
|
| 2036 | | - if (NULL === $data) return (!empty($cache) && (isset($cache['lifespan']) && time() < ($cache['lifespan'] + $this->dataDuration)));
|
| 2037 | | - else return (!empty($cache)
|
| 2038 | | - && (isset($cache[$dataPoint])
|
| 2039 | | - && $cache[$dataPoint] === $data)
|
| 2040 | | - && (isset($cache['lifespan']) && time() < ($cache['lifespan'] + $this->dataDuration)));
|
| 2041 | 1974 | }
|
| 2042 | 1975 | } |