10
10
/**
11
11
* Class DomainNameAPI_PHPLibrary
12
12
* @package DomainNameApi
13
- * @version 2.1.6
13
+ * @version 2.1.7
14
14
*/
15
15
16
16
@@ -25,7 +25,7 @@ class DomainNameAPI_PHPLibrary
25
25
/**
26
26
* Version of the library
27
27
*/
28
- const VERSION = '2.1.6 ' ;
28
+ const VERSION = '2.1.7 ' ;
29
29
30
30
const DEFAULT_NAMESERVERS = [
31
31
'ns1.domainnameapi.com ' ,
@@ -41,6 +41,84 @@ class DomainNameAPI_PHPLibrary
41
41
'*Price definition not found* ' ,
42
42
];
43
43
44
+ const DEFAULT_ERRORS = [
45
+ 'INVALID_DOMAIN_DETAILS ' => [
46
+ 'code ' => 'INVALID_DOMAIN_DETAILS ' ,
47
+ 'message ' => 'Invalid domain details! Details format is not valid ' ,
48
+ 'description ' => 'The provided domain details are not in the expected format '
49
+ ],
50
+ 'INVALID_CREDENTIALS ' => [
51
+ 'code ' => 'INVALID_CREDENTIALS ' ,
52
+ 'message ' => 'Invalid username and password ' ,
53
+ 'description ' => 'The provided API credentials are invalid '
54
+ ],
55
+ 'INVALID_DOMAIN_LIST ' => [
56
+ 'code ' => 'INVALID_DOMAIN_LIST ' ,
57
+ 'message ' => 'Domain info is not a valid array or more than one domain info has returned! ' ,
58
+ 'description ' => 'The domain list response is not in the expected format '
59
+ ],
60
+ 'INVALID_TLD_LIST ' => [
61
+ 'code ' => 'INVALID_TLD_LIST ' ,
62
+ 'message ' => 'TLD info is not a valid array or more than one TLD info has returned! ' ,
63
+ 'description ' => 'The TLD list response is not in the expected format '
64
+ ],
65
+ 'INVALID_RESPONSE ' => [
66
+ 'code ' => 'INVALID_RESPONSE ' ,
67
+ 'message ' => 'Invalid response received from server! Response is empty. ' ,
68
+ 'description ' => 'The API response is empty or null '
69
+ ],
70
+ 'INVALID_RESPONSE_FORMAT ' => [
71
+ 'code ' => 'INVALID_RESPONSE_FORMAT ' ,
72
+ 'message ' => 'Invalid response received from server! Response format is not valid. ' ,
73
+ 'description ' => 'The API response format is not in the expected structure '
74
+ ],
75
+ 'INVALID_RESPONSE_COUNT ' => [
76
+ 'code ' => 'INVALID_RESPONSE_COUNT ' ,
77
+ 'message ' => 'Invalid parameters passed to function! Response data contains more than one result! ' ,
78
+ 'description ' => 'The API response contains multiple results when only one was expected '
79
+ ],
80
+ 'INVALID_RESPONSE_CODE ' => [
81
+ 'code ' => 'INVALID_RESPONSE_CODE ' ,
82
+ 'message ' => 'Invalid parameters passed to function! Operation result or Error code not received from server ' ,
83
+ 'description ' => 'The API response is missing required operation result or error code fields '
84
+ ],
85
+ 'INVALID_RESPONSE_SOAP ' => [
86
+ 'code ' => 'INVALID_RESPONSE_SOAP ' ,
87
+ 'message ' => 'Invalid parameters passed to function! Soap return is not a valid array! ' ,
88
+ 'description ' => 'The SOAP response is not in a valid array format '
89
+ ],
90
+ 'INVALID_CONTACT_INFO ' => [
91
+ 'code ' => 'INVALID_CONTACT_INFO ' ,
92
+ 'message ' => 'Invalid response received from server! Contact info is not a valid array or more than one contact info has returned! ' ,
93
+ 'description ' => 'The contact information response is not in the expected format '
94
+ ],
95
+ 'INVALID_CONTACT_SAVE ' => [
96
+ 'code ' => 'INVALID_CONTACT_SAVE ' ,
97
+ 'message ' => 'Invalid response received from server! Contact info could not be saved! ' ,
98
+ 'description ' => 'The contact information could not be saved on the server '
99
+ ],
100
+ 'INVALID_DOMAIN_TRANSFER_REQUEST ' => [
101
+ 'code ' => 'INVALID_DOMAIN_TRANSFER_REQUEST ' ,
102
+ 'message ' => 'Invalid response received from server! Domain transfer request could not be completed! ' ,
103
+ 'description ' => 'The domain transfer request failed to complete '
104
+ ],
105
+ 'INVALID_DOMAIN_RENEW ' => [
106
+ 'code ' => 'INVALID_DOMAIN_RENEW ' ,
107
+ 'message ' => 'Invalid response received from server! Domain renew request could not be completed! ' ,
108
+ 'description ' => 'The domain renewal request failed to complete '
109
+ ],
110
+ 'INVALID_DOMAIN_REGISTER ' => [
111
+ 'code ' => 'INVALID_DOMAIN_REGISTER ' ,
112
+ 'message ' => 'Invalid response received from server! Domain register request could not be completed! ' ,
113
+ 'description ' => 'The domain registration request failed to complete '
114
+ ],
115
+ 'INVALID_DOMAIN_SYNC ' => [
116
+ 'code ' => 'INVALID_DOMAIN_SYNC ' ,
117
+ 'message ' => 'Invalid response received from server! Domain sync request could not be completed! ' ,
118
+ 'description ' => 'The domain synchronization request failed to complete '
119
+ ]
120
+ ];
121
+
44
122
const DEFAULT_CACHE_TTL = 512 ;
45
123
const DEFAULT_TIMEOUT = 20 ;
46
124
const DEFAULT_REASON = 'Owner request ' ;
@@ -179,7 +257,7 @@ private function setApplication()
179
257
{
180
258
$ dir = __DIR__ ;
181
259
$ this ->application = 'CORE ' ;
182
- $ this ->errorReportingPath = '' ;
260
+ $ this ->errorReportingPath = self :: APPLICATIONS [ ' CORE ' ][ ' path ' ] ;
183
261
$ this ->errorReportingDsn = self ::APPLICATIONS ['CORE ' ]['dsn ' ];
184
262
185
263
foreach (self ::APPLICATIONS as $ app => $ config ) {
@@ -190,13 +268,6 @@ private function setApplication()
190
268
break ;
191
269
}
192
270
}
193
-
194
- // Geçerli bir uygulama değilse CORE'a geri dön
195
- if (!array_key_exists ($ this ->application , self ::APPLICATIONS )) {
196
- $ this ->application = 'CORE ' ;
197
- $ this ->errorReportingPath = self ::APPLICATIONS ['CORE ' ]['path ' ];
198
- $ this ->errorReportingDsn = self ::APPLICATIONS ['CORE ' ]['dsn ' ];
199
- }
200
271
}
201
272
202
273
/**
@@ -401,8 +472,7 @@ public function GetResellerDetails()
401
472
$ resp ['balances ' ] = $ balances ;
402
473
} else {
403
474
$ resp ['result ' ] = 'ERROR ' ;
404
- $ resp ['error ' ] = $ this ->setError ("INVALID_CREDINENTIALS " , "Invalid response received from server! " ,
405
- "invalid username and password " );
475
+ $ resp ['error ' ] = $ this ->setError ("INVALID_CREDINENTIALS " );
406
476
}
407
477
408
478
@@ -555,10 +625,9 @@ public function GetList($extra_parameters = [])
555
625
} else {
556
626
// Set error
557
627
$ result ["result " ] = "ERROR " ;
558
- $ result ["error " ] = $ this ->setError ("INVALID_DOMAIN_LIST " , "Invalid response received from server! " ,
559
- "Domain info is not a valid array or more than one domain info has returned! " );
628
+ $ result ["error " ] = $ this ->setError ("INVALID_DOMAIN_LIST " );
560
629
561
- $ this ->sendErrorToSentryAsync (new Exception ("INVALID_DOMAIN_LIST: Invalid response received from server! Domain info is not a valid array or more than one domain info has returned! " ));
630
+ $ this ->sendErrorToSentryAsync (new Exception ("[ INVALID_DOMAIN_LIST] " . self :: DEFAULT_ERRORS [ ' INVALID_DOMAIN_LIST ' ][ ' description ' ] ));
562
631
}
563
632
return $ result ;
564
633
});
@@ -624,10 +693,9 @@ public function GetTldList($count = 20)
624
693
// Set error
625
694
$ result = [
626
695
'result ' => 'ERROR ' ,
627
- 'error ' => $ this ->setError ("INVALID_TLD_LIST " , "Invalid response received from server! " ,
628
- "Domain info is not a valid array or more than one domain info has returned! " )
696
+ 'error ' => $ this ->setError ("INVALID_TLD_LIST " )
629
697
];
630
- $ this ->sendErrorToSentryAsync (new Exception ("INVALID_TLD_LIST: Invalid response received from server! Domain info is not a valid array or more than one domain info has returned! " ));
698
+ $ this ->sendErrorToSentryAsync (new Exception ("[ INVALID_TLD_LIST] " . self :: DEFAULT_ERRORS [ ' INVALID_TLD_LIST ' ][ ' description ' ] ));
631
699
}
632
700
633
701
return $ result ;
@@ -655,22 +723,18 @@ public function GetDetails($domainName)
655
723
656
724
$ response = self ::parseCall (__FUNCTION__ , $ parameters , function ($ response ) {
657
725
$ data = $ response [key ($ response )];
658
-
659
- $ this ->sendErrorToSentryAsync (new Exception ("INVALID_DOMAIN_LIST: Invalid response received from server! Domain info is not a valid array or more than one domain info has returned! " ));
660
-
661
-
662
726
// If DomainInfo a valid array
663
727
if (isset ($ data ["DomainInfo " ]) && is_array ($ data ["DomainInfo " ])) {
664
728
// Parse domain info
729
+
665
730
$ result ["data " ] = $ this ->parseDomainInfo ($ data ["DomainInfo " ]);
666
731
$ result ["result " ] = "OK " ;
667
732
} else {
668
733
// Set error
669
734
$ result ["result " ] = "ERROR " ;
670
- $ result ["error " ] = $ this ->setError ("INVALID_DOMAIN_LIST " , "Invalid response received from server! " ,
671
- "Domain info is not a valid array or more than one domain info has returned! " );
735
+ $ result ["error " ] = $ this ->setError ("INVALID_DOMAIN_DETAILS " );
672
736
673
- $ this ->sendErrorToSentryAsync (new Exception ("INVALID_DOMAIN_LIST: Invalid response received from server! Domain info is not a valid array or more than one domain info has returned! " ));
737
+ $ this ->sendErrorToSentryAsync (new Exception ("[INVALID_DOMAIN_DETAILS] " . self :: DEFAULT_ERRORS [ ' INVALID_DOMAIN_DETAILS ' ][ ' description ' ] ));
674
738
}
675
739
return $ result ;
676
740
});
@@ -911,11 +975,10 @@ public function GetContacts($domainName)
911
975
} else {
912
976
// Set error
913
977
$ result = [
914
- 'error ' => $ this ->setError ("INVALID_CONTACT_INTO " , "Invalid response received from server! " ,
915
- "Contact info is not a valid array or more than one contact info has returned! " ),
978
+ 'error ' => $ this ->setError ("INVALID_CONTACT_INFO " ),
916
979
'result ' => 'ERROR '
917
980
];
918
- $ this ->sendErrorToSentryAsync (new Exception ("INVALID_CONTACT_INTO: Invalid response received from server! Contact info is not a valid array or more than one contact info has returned! " ));
981
+ $ this ->sendErrorToSentryAsync (new Exception ("[INVALID_CONTACT_INFO] " . self :: DEFAULT_ERRORS [ ' INVALID_CONTACT_INFO ' ][ ' description ' ] ));
919
982
}
920
983
return $ result ;
921
984
});
@@ -958,11 +1021,10 @@ public function SaveContacts($domainName, $contacts)
958
1021
// Set error
959
1022
$ result = [
960
1023
'result ' => 'ERROR ' ,
961
- 'error ' => $ this ->setError ("INVALID_CONTACT_SAVE " , "Invalid response received from server! " ,
962
- "Contact info is not a valid array or more than one contact info has returned! " )
1024
+ 'error ' => $ this ->setError ("INVALID_CONTACT_SAVE " )
963
1025
];
964
1026
965
- $ this ->sendErrorToSentryAsync (new Exception ("INVALID_CONTACT_SAVE: Invalid response received from server! Contact info is not a valid array or more than one contact info has returned! " ));
1027
+ $ this ->sendErrorToSentryAsync (new Exception ("[ INVALID_CONTACT_SAVE] " . self :: DEFAULT_ERRORS [ ' INVALID_CONTACT_SAVE ' ][ ' description ' ] ));
966
1028
}
967
1029
return $ result ;
968
1030
});
@@ -1012,11 +1074,9 @@ public function Transfer($domainName, $eppCode, $period)
1012
1074
// Set error
1013
1075
$ result = [
1014
1076
'result ' => 'ERROR ' ,
1015
- 'data ' => $ this ->setError ("INVALID_DOMAIN_TRANSFER_REQUEST " ,
1016
- "Invalid response received from server! " ,
1017
- "Domain info is not a valid array or more than one domain info has returned! " )
1077
+ 'data ' => $ this ->setError ("INVALID_DOMAIN_TRANSFER_REQUEST " )
1018
1078
];
1019
- $ this ->sendErrorToSentryAsync (new Exception ("INVALID_DOMAIN_TRANSFER_REQUEST: Invalid response received from server! Domain info is not a valid array or more than one domain info has returned! " ));
1079
+ $ this ->sendErrorToSentryAsync (new Exception ("[ INVALID_DOMAIN_TRANSFER_REQUEST] " . self :: DEFAULT_ERRORS [ ' INVALID_DOMAIN_TRANSFER_REQUEST ' ][ ' description ' ] ));
1020
1080
}
1021
1081
return $ result ;
1022
1082
});
@@ -1148,10 +1208,9 @@ public function Renew($domainName, $period)
1148
1208
} else {
1149
1209
return [
1150
1210
'result ' => 'ERROR ' ,
1151
- 'error ' => $ this ->setError ("INVALID_DOMAIN_RENEW " , "Invalid response received from server! " ,
1152
- "Domain info is not a valid array or more than one domain info has returned! " )
1211
+ 'error ' => $ this ->setError ("INVALID_DOMAIN_RENEW " )
1153
1212
];
1154
- $ this ->sendErrorToSentryAsync (new Exception ("INVALID_DOMAIN_RENEW: Invalid response received from server! Domain info is not a valid array or more than one domain info has returned! " ));
1213
+ $ this ->sendErrorToSentryAsync (new Exception ("[ INVALID_DOMAIN_RENEW] " . self :: DEFAULT_ERRORS [ ' INVALID_DOMAIN_RENEW ' ][ ' description ' ] ));
1155
1214
}
1156
1215
});
1157
1216
@@ -1232,10 +1291,9 @@ public function RegisterWithContactInfo(
1232
1291
// Set error
1233
1292
$ result = [
1234
1293
'result ' => 'ERROR ' ,
1235
- 'error ' => $ this ->setError ("INVALID_DOMAIN_REGISTER " , "Invalid response received from server! " ,
1236
- "Domain info is not a valid array or more than one domain info has returned! " )
1294
+ 'error ' => $ this ->setError ("INVALID_DOMAIN_REGISTER " )
1237
1295
];
1238
- $ this ->sendErrorToSentryAsync (new Exception ("INVALID_DOMAIN_REGISTER: Invalid response received from server! Domain info is not a valid array or more than one domain info has returned! " ));
1296
+ $ this ->sendErrorToSentryAsync (new Exception ("[ INVALID_DOMAIN_REGISTER] " . self :: DEFAULT_ERRORS [ ' INVALID_DOMAIN_REGISTER ' ][ ' description ' ] ));
1239
1297
}
1240
1298
return $ result ;
1241
1299
});
@@ -1303,11 +1361,10 @@ public function SyncFromRegistry($domainName)
1303
1361
} else {
1304
1362
// Set error
1305
1363
$ result = [
1306
- 'error ' => $ this ->setError ("INVALID_DOMAIN_SYNC " , "Invalid response received from server! " ,
1307
- "Domain info is not a valid array or more than one domain info has returned! " ),
1364
+ 'error ' => $ this ->setError ("INVALID_DOMAIN_SYNC " ),
1308
1365
'result ' => 'ERROR '
1309
1366
];
1310
- $ this ->sendErrorToSentryAsync (new Exception ("INVALID_DOMAIN_SYNC: Invalid response received from server! Domain info is not a valid array or more than one domain info has returned! " ));
1367
+ $ this ->sendErrorToSentryAsync (new Exception ("[ INVALID_DOMAIN_SYNC] " . self :: DEFAULT_ERRORS [ ' INVALID_DOMAIN_SYNC ' ][ ' description ' ] ));
1311
1368
}
1312
1369
1313
1370
return $ result ;
@@ -1346,17 +1403,16 @@ private function parseError($response, $trace = true)
1346
1403
// Set error data
1347
1404
$ result = [];
1348
1405
$ result ["Code " ] = "INVALID_RESPONSE " ;
1349
- $ result ["Message " ] = " Invalid response or no response received from server! " ;
1350
- $ result ["Details " ] = " SOAP Connection returned null value! " ;
1406
+ $ result ["Message " ] = self :: DEFAULT_ERRORS [ ' INVALID_RESPONSE ' ][ ' message ' ] ;
1407
+ $ result ["Details " ] = self :: DEFAULT_ERRORS [ ' INVALID_RESPONSE ' ][ ' description ' ] ;
1351
1408
} elseif (!is_array ($ response )) {
1352
1409
// Set error data
1353
1410
$ result = [];
1354
- $ result ["Code " ] = "INVALID_RESPONSE " ;
1355
- $ result ["Message " ] = " Invalid response or no response received from server! " ;
1356
- $ result ["Details " ] = " SOAP Connection returned non-array value! " ;
1411
+ $ result ["Code " ] = "INVALID_RESPONSE_FORMAT " ;
1412
+ $ result ["Message " ] = self :: DEFAULT_ERRORS [ ' INVALID_RESPONSE_FORMAT ' ][ ' message ' ] ;
1413
+ $ result ["Details " ] = self :: DEFAULT_ERRORS [ ' INVALID_RESPONSE_FORMAT ' ][ ' description ' ] ;
1357
1414
} elseif (strtolower (key ($ response )) == "faultstring " ) {
1358
1415
// Handle soap fault
1359
-
1360
1416
$ result = [];
1361
1417
$ result ["Code " ] = "" ;
1362
1418
$ result ["Message " ] = "" ;
@@ -1383,22 +1439,21 @@ private function parseError($response, $trace = true)
1383
1439
} elseif (count ($ response ) != 1 ) {
1384
1440
// Set error data
1385
1441
$ result = [];
1386
- $ result ["Code " ] = "INVALID_RESPONSE " ;
1387
- $ result ["Message " ] = " Invalid response or no response received from server! " ;
1388
- $ result ["Details " ] = " Response data contains more than one result! Only one result accepted! " ;
1442
+ $ result ["Code " ] = "INVALID_RESPONSE_COUNT " ;
1443
+ $ result ["Message " ] = self :: DEFAULT_ERRORS [ ' INVALID_RESPONSE_COUNT ' ][ ' message ' ] ;
1444
+ $ result ["Details " ] = self :: DEFAULT_ERRORS [ ' INVALID_RESPONSE_COUNT ' ][ ' description ' ] ;
1389
1445
} elseif (!isset ($ response [key ($ response )]["OperationResult " ]) || !isset ($ response [key ($ response )]["ErrorCode " ])) {
1390
1446
// Set error data
1391
1447
$ result = [];
1392
- $ result ["Code " ] = "INVALID_RESPONSE " ;
1393
- $ result ["Message " ] = " Invalid response or no response received from server! " ;
1394
- $ result ["Details " ] = " Operation result or Error code not received from server! " ;
1448
+ $ result ["Code " ] = "INVALID_RESPONSE_CODE " ;
1449
+ $ result ["Message " ] = self :: DEFAULT_ERRORS [ ' INVALID_RESPONSE_CODE ' ][ ' message ' ] ;
1450
+ $ result ["Details " ] = self :: DEFAULT_ERRORS [ ' INVALID_RESPONSE_CODE ' ][ ' description ' ] ;
1395
1451
} elseif (strtoupper ($ response [key ($ response )]["OperationResult " ]) != "SUCCESS " ) {
1396
1452
// Set error data
1397
1453
$ result = [
1398
1454
"Code " => '' ,
1399
1455
"Message " => 'Failed ' ,
1400
1456
"Details " => '' ,
1401
-
1402
1457
];
1403
1458
1404
1459
if (isset ($ response [key ($ response )]["OperationMessage " ])) {
@@ -1416,7 +1471,7 @@ private function parseError($response, $trace = true)
1416
1471
}
1417
1472
1418
1473
if (isset ($ result ["Code " ]) && $ trace === true ) {
1419
- $ this ->sendErrorToSentryAsync (new Exception ("API_ERROR: " . $ result ["Code " ] . " - " . $ result ["Message " ] . " - " . $ result ["Details " ]));
1474
+ $ this ->sendErrorToSentryAsync (new Exception ("[ API_ERROR] : " . $ result ["Code " ] . " - " . $ result ["Message " ] . " - " . $ result ["Details " ]));
1420
1475
}
1421
1476
1422
1477
return $ result ;
@@ -1436,17 +1491,24 @@ private function hasError($response)
1436
1491
/**
1437
1492
* Set error message
1438
1493
*
1439
- * @param string $Code Error code
1440
- * @param string $Message Error message
1441
- * @param string $Details Error details
1494
+ * @param string $code Error code
1495
+ * @param string $message Error message
1496
+ * @param string $details Error details
1442
1497
* @return array Error information
1443
1498
*/
1444
- private function setError ($ Code , $ Message , $ Details )
1499
+ private function setError ($ code , $ message = '' , $ details = '' )
1445
1500
{
1446
- $ result = [];
1447
- $ result ["Code " ] = $ Code ;
1448
- $ result ["Message " ] = $ Message ;
1449
- $ result ["Details " ] = $ Details ;
1501
+ $ result = [];
1502
+ if (isset (self ::DEFAULT_ERRORS [$ code ])) {
1503
+ $ error = self ::DEFAULT_ERRORS [$ code ];
1504
+ $ result ["Code " ] = $ error ['code ' ];
1505
+ $ result ["Message " ] = $ error ['message ' ];
1506
+ $ result ["Details " ] = $ error ['description ' ];
1507
+ } else {
1508
+ $ result ["Code " ] = $ code ;
1509
+ $ result ["Message " ] = $ message ;
1510
+ $ result ["Details " ] = $ details ;
1511
+ }
1450
1512
return $ result ;
1451
1513
}
1452
1514
@@ -1746,7 +1808,7 @@ private function parseCall($fn, $parameters, $_callback): array
1746
1808
}
1747
1809
} catch (SoapFault $ ex ) {
1748
1810
$ result ["result " ] = "ERROR " ;
1749
- $ result ["error " ] = $ this ->setError ('INVALID_RESPONSE ' , ' Invalid response occurred ' , $ ex ->getMessage ());
1811
+ $ result ["error " ] = $ this ->setError ('INVALID_RESPONSE_SOAP ' , self :: DEFAULT_ERRORS [ ' INVALID_RESPONSE_SOAP ' ][ ' description ' ] , $ ex ->getMessage ());
1750
1812
$ this ->sendErrorToSentryAsync ($ ex );
1751
1813
} catch (Exception $ ex ) {
1752
1814
$ result ["result " ] = "ERROR " ;
0 commit comments