CheckOneDomain.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\App\Libs\Api\ENom\Method;
  3. /**
  4. * Description of CheckOneDomain
  5. *
  6. * @author Rafał Ossowski <rafal.os@modulesgarden.com>
  7. */
  8. class CheckOneDomain extends AbstractMethod
  9. {
  10. protected $domain;
  11. protected $tld;
  12. public function execute($params)
  13. {
  14. $this->domain = str_replace(' ', '', $params['sld']);
  15. $this->tld = $params['tld'];
  16. return $this->checkOneDomain();
  17. }
  18. public function checkOneDomain()
  19. {
  20. $response = $this->request->post([
  21. 'Command' => 'check',
  22. 'SLD' => $this->idnaConvert->encode(strtolower($this->domain)),
  23. 'TLD' => $this->idnaConvert->encode(strtolower(substr($this->tld, 1))),
  24. 'ResponseType' => 'xml',
  25. 'UID' => $this->settings['username'],
  26. 'PW' => $this->settings['password'],
  27. ]);
  28. return $this->formatResponse($response);
  29. }
  30. protected function formatResponse($response)
  31. {
  32. $resultData = [];
  33. if ($response && $response->isSuccess())
  34. {
  35. $response = $response->getBody();
  36. $status = ($response->Done == 'true') ? $this->getStatus((int)$response->RRPCode) : self::RESPONSE_RESULT_ERROR;
  37. }
  38. else
  39. {
  40. $status = self::RESPONSE_RESULT_ERROR;
  41. }
  42. $resultData[] = [
  43. 'sld' => $this->domain,
  44. 'tld' => $this->tld,
  45. 'status' => $status
  46. ];
  47. return $resultData;
  48. }
  49. protected function getStatus($rRPCode)
  50. {
  51. $status = self::RESPONSE_RESULT_ERROR;
  52. switch ($rRPCode)
  53. {
  54. case 211:
  55. $status = self::RESPONSE_RESULT_TAKEN;
  56. case 210:
  57. $status = self::RESPONSE_RESULT_FREE;
  58. }
  59. return $status;
  60. }
  61. }