mirror of
https://github.com/getnamingo/registry.git
synced 2025-05-15 09:07:00 +02:00
Work on #52
This commit is contained in:
parent
4503cd0073
commit
3605eaece8
4 changed files with 33 additions and 9 deletions
|
@ -291,17 +291,29 @@ function extractDomainAndTLD($urlString) {
|
||||||
$parts = parse_url($urlString);
|
$parts = parse_url($urlString);
|
||||||
$host = $parts['host'] ?? $urlString;
|
$host = $parts['host'] ?? $urlString;
|
||||||
|
|
||||||
|
// Sort test TLDs by length (longest first) to match the longest possible TLD
|
||||||
|
usort($testTlds, function ($a, $b) {
|
||||||
|
return strlen($b) - strlen($a);
|
||||||
|
});
|
||||||
|
|
||||||
// Check if the TLD is a known test TLD
|
// Check if the TLD is a known test TLD
|
||||||
foreach ($testTlds as $testTld) {
|
foreach ($testTlds as $testTld) {
|
||||||
if (str_ends_with($host, "$testTld")) {
|
if (str_ends_with($host, "$testTld")) {
|
||||||
// Handle the test TLD case
|
// Handle the test TLD case
|
||||||
$hostParts = explode('.', $host);
|
$tldLength = strlen($testTld) + 1; // +1 for the dot
|
||||||
$tld = array_pop($hostParts);
|
$hostWithoutTld = substr($host, 0, -$tldLength);
|
||||||
|
$hostParts = explode('.', $hostWithoutTld);
|
||||||
$sld = array_pop($hostParts);
|
$sld = array_pop($hostParts);
|
||||||
return ['domain' => $sld, 'tld' => $tld];
|
if (strpos($testTld, '.') === 0) {
|
||||||
|
$testTld = ltrim($testTld, '.');
|
||||||
|
}
|
||||||
|
return [
|
||||||
|
'domain' => implode('.', $hostParts) ? implode('.', $hostParts) . '.' . $sld : $sld,
|
||||||
|
'tld' => $testTld
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use the PHP Domain Parser library for real TLDs
|
// Use the PHP Domain Parser library for real TLDs
|
||||||
$tlds = TopLevelDomains::fromString($fileContent);
|
$tlds = TopLevelDomains::fromString($fileContent);
|
||||||
$domain = Domain::fromIDNA2008($host);
|
$domain = Domain::fromIDNA2008($host);
|
||||||
|
|
|
@ -26,4 +26,4 @@ MAIL_API_PROVIDER='sendgrid'
|
||||||
|
|
||||||
STRIPE_SECRET_KEY='stripe-secret-key'
|
STRIPE_SECRET_KEY='stripe-secret-key'
|
||||||
|
|
||||||
TEST_TLDS=.test,.xx
|
TEST_TLDS=.test,.com.test
|
|
@ -14,5 +14,5 @@ return [
|
||||||
'epp_prefix' => 'namingo',
|
'epp_prefix' => 'namingo',
|
||||||
'ssl_cert' => '',
|
'ssl_cert' => '',
|
||||||
'ssl_key' => '',
|
'ssl_key' => '',
|
||||||
'test_tlds' => '.test,.xx',
|
'test_tlds' => '.test,.com.test',
|
||||||
];
|
];
|
|
@ -247,15 +247,27 @@ function extractDomainAndTLD($urlString) {
|
||||||
// Parse the URL to get the host
|
// Parse the URL to get the host
|
||||||
$parts = parse_url($urlString);
|
$parts = parse_url($urlString);
|
||||||
$host = $parts['host'] ?? $urlString;
|
$host = $parts['host'] ?? $urlString;
|
||||||
|
|
||||||
|
// Sort test TLDs by length (longest first) to match the longest possible TLD
|
||||||
|
usort($testTlds, function ($a, $b) {
|
||||||
|
return strlen($b) - strlen($a);
|
||||||
|
});
|
||||||
|
|
||||||
// Check if the TLD is a known test TLD
|
// Check if the TLD is a known test TLD
|
||||||
foreach ($testTlds as $testTld) {
|
foreach ($testTlds as $testTld) {
|
||||||
if (str_ends_with($host, "$testTld")) {
|
if (str_ends_with($host, "$testTld")) {
|
||||||
// Handle the test TLD case
|
// Handle the test TLD case
|
||||||
$hostParts = explode('.', $host);
|
$tldLength = strlen($testTld) + 1; // +1 for the dot
|
||||||
$tld = array_pop($hostParts);
|
$hostWithoutTld = substr($host, 0, -$tldLength);
|
||||||
|
$hostParts = explode('.', $hostWithoutTld);
|
||||||
$sld = array_pop($hostParts);
|
$sld = array_pop($hostParts);
|
||||||
return ['domain' => $sld, 'tld' => $tld];
|
if (strpos($testTld, '.') === 0) {
|
||||||
|
$testTld = ltrim($testTld, '.');
|
||||||
|
}
|
||||||
|
return [
|
||||||
|
'domain' => implode('.', $hostParts) ? implode('.', $hostParts) . '.' . $sld : $sld,
|
||||||
|
'tld' => $testTld
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue