pierreminiggio / tld-api
PHP client for the tld-api TLD validation API (https://tld-api.ggio.fr), with local file caching
Requires
- php: >=8.0
- ext-curl: *
- ext-json: *
Requires (Dev)
- phpunit/phpunit: ^9.6
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
PHP client for the tld-api API, which validates whether a TLD (Top-Level Domain) exists against the IANA TLD list.
Responses are cached locally in a JSON file for 2 months, to avoid hitting the remote API on every call.
Installation
composer require pierreminiggio/tld-api
Usage
use PierreMiniggio\TLDAPI\Validator; $validator = new Validator(); $validator->validate('com'); // true $validator->validate('notarealtld'); // false $validator->validate('澳門'); // true, non-ASCII TLDs are supported
The first call for a given TLD hits the remote API and stores the result in the local
cache (cache/tlds.json, ordered alphabetically by TLD). Any call made within the next
2 months for the same TLD is served from that cache. Once the cached entry is older than
2 months, the next call refreshes it from the API.
Cache folder permissions
The cache/ folder needs to be writable by the PHP process. If it isn't, validate()
throws a RuntimeException telling you exactly which chmod -R 777 <folder> command to run.
Running the tests
composer install vendor/bin/phpunit