Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 43 |
| ApiObject | |
0.00% |
0 / 1 |
|
0.00% |
0 / 6 |
240 | |
0.00% |
0 / 43 |
| __construct | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| setId | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| setClass | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| loadStatus | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 6 |
|||
| convert | |
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 13 |
|||
| convertbulk | |
0.00% |
0 / 1 |
30 | |
0.00% |
0 / 18 |
|||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * CNIC\HEXONET |
| 5 | * Copyright © CentralNic Group PLC |
| 6 | */ |
| 7 | |
| 8 | namespace CNIC\HEXONET; |
| 9 | |
| 10 | /** |
| 11 | * HEXONET API Object |
| 12 | * |
| 13 | * @package CNIC\HEXONET |
| 14 | */ |
| 15 | |
| 16 | class ApiObject implements \CNIC\ApiObjectInterface |
| 17 | { |
| 18 | /** |
| 19 | * @var string object identifier |
| 20 | */ |
| 21 | protected $id = null; |
| 22 | /** |
| 23 | * @var string object class/type |
| 24 | */ |
| 25 | protected $class = null; |
| 26 | /** |
| 27 | * @var Client registrar's client instance |
| 28 | */ |
| 29 | protected $cl = null; |
| 30 | /** |
| 31 | * @var Response|null registrar's status response |
| 32 | */ |
| 33 | protected $status = null; |
| 34 | |
| 35 | /** |
| 36 | * Constructor |
| 37 | * @param \CNIC\HEXONET\Client $cf registrar's client instance |
| 38 | */ |
| 39 | public function __construct($cf) |
| 40 | { |
| 41 | $this->cl = $cf; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Set the related Object ID |
| 46 | * @param string $objectid object id |
| 47 | * @return $this |
| 48 | */ |
| 49 | public function setId(string $objectid): self |
| 50 | { |
| 51 | $this->id = $objectid; |
| 52 | return $this; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Set the Object Class |
| 57 | * @param string $objectclass object class |
| 58 | * @return $this |
| 59 | */ |
| 60 | public function setClass(string $objectclass): self |
| 61 | { |
| 62 | $this->class = $objectclass; |
| 63 | return $this->loadStatus(); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Load Status Data |
| 68 | * @param bool $refresh trigger fresh data load, by default false |
| 69 | * @return $this |
| 70 | */ |
| 71 | public function loadStatus(bool $refresh = false): self |
| 72 | { |
| 73 | if ( |
| 74 | isset($this->status) |
| 75 | || $refresh |
| 76 | ) { |
| 77 | $this->status = $this->cl->request([ |
| 78 | "COMMAND" => "Status" . ucfirst(strtolower($this->class)), |
| 79 | "DOMAIN" => $this->id |
| 80 | ]); |
| 81 | } |
| 82 | return $this; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * IDN Conversion |
| 87 | * @return array |
| 88 | */ |
| 89 | public function convert(): array |
| 90 | { |
| 91 | if (preg_match("/^DOMAIN|DNSZONE|NAMESERVER$/i", $this->class)) {//TODO |
| 92 | $r = $this->cl->request([ |
| 93 | "COMMAND" => "ConvertIDN", |
| 94 | "DOMAIN" => [$this->id] |
| 95 | ]); |
| 96 | if ($r->isSuccess()) { |
| 97 | $d = $r->getRecord(0); |
| 98 | if (!empty($d["IDN"])) { |
| 99 | return [ |
| 100 | "idn" => $d["IDN"], |
| 101 | "punycode" => $d["ACE"], |
| 102 | "objectid" => $this->id, |
| 103 | "converted" => true |
| 104 | ]; |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | return [ |
| 109 | "idn" => $this->id, |
| 110 | "punycode" => $this->id, |
| 111 | "objectid" => $this->id, |
| 112 | "converted" => false |
| 113 | ]; |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Bulk IDN Conversion |
| 118 | * @param array $domains List of Domains |
| 119 | * @return array |
| 120 | */ |
| 121 | public function convertbulk($domains): array |
| 122 | { |
| 123 | $r = $this->cl->request([ |
| 124 | "COMMAND" => "ConvertIDN", |
| 125 | "DOMAIN" => $domains |
| 126 | ]); |
| 127 | $list = []; |
| 128 | foreach ($domains as $domain) { |
| 129 | $list[] = [ |
| 130 | "idn" => $domain, |
| 131 | "punycode" => $domain, |
| 132 | "domain" => $domain |
| 133 | ]; |
| 134 | } |
| 135 | if ($r->isSuccess()) { |
| 136 | $recs = $r->getRecords(); |
| 137 | foreach ($recs as $idx => $rec) { |
| 138 | $d = $rec->getData(); |
| 139 | if (empty($d["IDN"])) { |
| 140 | continue; |
| 141 | } |
| 142 | $list[$idx]["idn"] = $d["IDN"]; |
| 143 | $list[$idx]["punycode"] = $d["ACE"]; |
| 144 | } |
| 145 | } |
| 146 | return $list; |
| 147 | } |
| 148 | } |