CheckMoreDomains.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\App\Libs\Api\OpenSRS\Method;
  3. /**
  4. * Description of CheckMoreDomains
  5. *
  6. * @author Rafał Ossowski <rafal.os@modulesgarden.com>
  7. */
  8. class CheckMoreDomains extends AbstractMethod
  9. {
  10. protected $domainList = [];
  11. protected $returnData = [];
  12. public function execute($records)
  13. {
  14. foreach ($this->getDomainList($records) as $domain => $tlds)
  15. {
  16. $response = $this->request->process(
  17. 'json', json_encode([
  18. 'func' => 'fastDomainLookup',
  19. 'data' => [
  20. 'domain' => $this->idnaConvert->encode(strtolower($domain)),
  21. 'selected' => implode(';', $tlds),
  22. 'alldomains' => implode(';', $tlds)
  23. ]
  24. ])
  25. )->resultFormatted;
  26. $this->returnData = array_merge($this->returnData, json_decode($response));
  27. }
  28. return $this->formatResponse();
  29. }
  30. protected function getDomainList($records = [])
  31. {
  32. $this->domainList = [];
  33. foreach ($records as $record)
  34. {
  35. $this->domainList[$record['sld']][] = "." . $this->idnaConvert->encode(strtolower($record['tld']));
  36. }
  37. return $this->domainList;
  38. }
  39. protected function formatResponse()
  40. {
  41. $returnData = [];
  42. foreach ($this->returnData as $record)
  43. {
  44. $returnData[] = [
  45. 'sld' => $this->idnaConvert->decode($record->domain),
  46. 'tld' => $this->idnaConvert->decode($record->tld),
  47. 'status' => $this->choseResult($record->result)
  48. ];
  49. }
  50. return $returnData;
  51. }
  52. protected function choseResult($return)
  53. {
  54. switch ($return)
  55. {
  56. case 'Available':
  57. return self::RESPONSE_RESULT_FREE;
  58. case 'Taken':
  59. return self::RESPONSE_RESULT_TAKEN;
  60. default:
  61. return self::RESPONSE_RESULT_ERROR;
  62. }
  63. }
  64. }