layershifter/tld-support
Lightweight PHP utilities for parsing domains and top-level domains. Split URLs into subdomain, domain, and TLD, validate hostnames, and work with public suffix data. A small dependency for the tld-extract ecosystem, useful for domain validation, sorting, and extraction tasks.
Treat layershifter/tld-support as an internal transitive dependency, not the package you adopt directly. In a normal Laravel app you should be using layershifter/tld-extract or layershifter/tld-database; TLDSupport is the shared glue those packages pull in.
Minimal steps:
# Find out why it is installed and which version is locked
composer show layershifter/tld-support
composer why layershifter/tld-support
# For a domain-parsing use case, depend on the higher-level package:
composer require layershifter/tld-extract
Look first at:
vendor/layershifter/tld-support/src/ to see what is actually public in your locked version.layershifter/tld-extract or layershifter/tld-database, because those are the intended entry points.composer.lock to confirm the exact TLDSupport version and whether it is only present as a transitive dependency.First practical use case: normalize and inspect a domain submitted by a user, e.g. from a signup form or tenant subdomain:
use LayerShifter\TLDExtract\Extract;
$extract = new Extract();
$result = $extract->parse('https://www.example.co.uk/path');
$host = $result->getHostname(); // www.example.co.uk
$subdomain = $result->getSubdomain(); // www
$domain = $result->getDomain(); // example
$suffix = $result->getSuffix(); // co.uk
$registrableDomain = $domain . '.' . $suffix; // example.co.uk
Verify method names against your locked version before relying on them in application code.
namespace App\Services;
use LayerShifter\TLDExtract\Extract;
class DomainService
{
public function __construct(private Extract $extract)
{
}
public function registrableDomain(string $input): ?string
{
$input = trim(strtolower($input));
$input = preg_replace('#^https?://#', '', $input);
$input = explode('/', $input)[0] ?? $input;
$input = explode(':', $input)[0] ?? $input;
$result = $this->extract->parse($input);
if (! $result || ! $result->getDomain() || ! $result->getSuffix()) {
return null;
}
return $result->getDomain() . '.' . $result->getSuffix();
}
}
foo.bar.co.uk?” → TLD extractor / Public Suffix List logic.co.uk, com.au, and private suffixes such as github.io.$this->app->singleton(\LayerShifter\TLDExtract\Extract::class, function () {
return new \LayerShifter\TLDExtract\Extract();
});
localhost, IP addresses, example.com., uppercase input, [email protected], example.co.uk, foo.blogspot.com, wildcard suffixes, and punycode domains.jeremykendall/php-domain-parser or bakame/domain-parser.composer why shows it is only required by TLDExtract/TLDDatabase, leave it alone. Adding it directly creates unnecessary coupling.co.uk is a public suffix but not a TLD. Do not try to derive registrable domains from a TLD database alone.blogspot.com or github.io is treated as a suffix depends on the data and options used. Decide explicitly whether you want private domains included.*.ck and !www.ck require a real PSL implementation; do not hand-roll suffix matching with explode('.').example.рф and xn--... may represent the same domain. Normalize once at the boundary and store one canonical form.localhost, IPs, ports, and trailing dots often return null/false or unexpected results. Handle them explicitly before calling the parser.composer show, composer why, and vendor/layershifter/tld-support/src rather than relying on old blog posts or the package README for exact class names.How can I help you explore Laravel packages today?