### Domain Parser Configuration Example Source: https://context7.com/kevindierkx/laravel-domain-parser/llms.txt Example configuration for Laravel Domain Parser, showing settings for cache driver, TTL, HTTP client options, and list URIs. ```php // config/domain-parser.php return [ // Laravel cache store to use (defaults to CACHE_DRIVER env var, fallback 'file') 'cache_driver' => env('CACHE_DRIVER', 'file'), // How long (in minutes) to keep PSL/TLD lists cached; null = forever 'cache_ttl' => 3600, // Optional GuzzleHttp client options (timeouts, proxies, etc.) 'http_client_options' => [ 'timeout' => 10, 'connect_timeout' => 5, ], // Override the default Public Suffix List source URI 'uri_public_suffix_list' => 'https://publicsuffix.org/list/public_suffix_list.dat', // Override the default IANA TLD list source URI 'uri_top_level_domain_list' => 'https://data.iana.org/TLD/tlds-alpha-by-domain.txt', ]; ``` -------------------------------- ### Run Project Tests Source: https://github.com/kevindierkx/laravel-domain-parser/blob/master/README.md To execute the project's tests, use this command in the project's root directory. Ensure you have Composer installed. ```bash composer test ``` -------------------------------- ### Install Laravel Domain Parser via Composer Source: https://github.com/kevindierkx/laravel-domain-parser/blob/master/docs/10-getting-started.md Use this command to add the package to your Laravel project dependencies. ```bash composer require bakame/laravel-domain-parser ``` -------------------------------- ### Publish Configuration File Source: https://github.com/kevindierkx/laravel-domain-parser/blob/master/docs/10-getting-started.md Run this Artisan command to publish the package's configuration file to your application's config directory. ```bash php artisan vendor:publish --provider="Bakame\Laravel\Pdp\ServiceProvider" --tag=config ``` -------------------------------- ### Facade: `Rules` Source: https://context7.com/kevindierkx/laravel-domain-parser/llms.txt The `Rules` facade proxies `\Pdp\Rules` (the `PublicSuffixList` instance), providing the full PHP Domain Parser API for resolving domain names. ```APIDOC ## Facade: `Rules` ### Description The `Rules` facade (`Bakame\Laravel\Pdp\Facades\Rules`) proxies `\Pdp\Rules` (the `PublicSuffixList` instance), bound in the IoC container as `pdp.rules`. It exposes the full PHP Domain Parser `Rules` API for resolving domain names against the Public Suffix List. ### Methods - **resolve(string $domain)**: Resolves a domain against the Public Suffix List. - **getICANNDomain(string $domain)**: Resolves a domain against the ICANN section of the Public Suffix List. ### Usage Example ```php use Bakame\Laravel\Pdp\Facades\Rules; // Resolve a domain against the Public Suffix List $result = Rules::resolve('www.example.co.uk'); echo $result->registrableDomain()->toString(); // => 'example.co.uk' echo $result->subDomain()->toString(); // => 'www' echo $result->suffix()->toString(); // => 'co.uk' echo $result->suffix()->isICANN(); // => true echo $result->suffix()->isPrivate(); // => false echo $result->suffix()->isKnown(); // => true // Resolve using ICANN section only $icann = Rules::getICANNDomain('www.github.com'); echo $icann->registrableDomain()->toString(); // => 'github.com' // IoC container alternative $rules = app('pdp.rules'); $result = $rules->resolve('blog.example.com'); ``` ``` -------------------------------- ### Resolve Domain Against Public Suffix List using Rules Facade Source: https://context7.com/kevindierkx/laravel-domain-parser/llms.txt Use the `Rules` facade to proxy `Pdp\Rules` and resolve domain names against the Public Suffix List, accessing registrable domain, sub-domain, and suffix information. ```php use Bakame\Laravel\Pdp\Facades\Rules; // Resolve a domain against the Public Suffix List $result = Rules::resolve('www.example.co.uk'); echo $result->registrableDomain()->toString(); // => 'example.co.uk' echo $result->subDomain()->toString(); // => 'www' echo $result->suffix()->toString(); // => 'co.uk' echo $result->suffix()->isICANN(); // => true echo $result->suffix()->isPrivate(); // => false echo $result->suffix()->isKnown(); // => true // Resolve using ICANN section only $icann = Rules::getICANNDomain('www.github.com'); echo $icann->registrableDomain()->toString(); // => 'github.com' // IoC container alternative $rules = app('pdp.rules'); $result = $rules->resolve('blog.example.com'); ``` -------------------------------- ### Access PublicSuffixList and TopLevelDomainList via Facade Source: https://context7.com/kevindierkx/laravel-domain-parser/llms.txt Use the `DomainParser` facade to retrieve cached or fresh instances of `PublicSuffixList` and `TopLevelDomainList`. ```php use Bakame\Laravel\Pdp\Facades\DomainParser; // Get the cached PublicSuffixList instance $rules = DomainParser::getRules(); // Get a fresh (force-refreshed) PublicSuffixList instance $rules = DomainParser::getRules(true); // Get the cached TopLevelDomainList instance $tlds = DomainParser::getTopLevelDomains(); // Get a fresh TopLevelDomainList instance $tlds = DomainParser::getTopLevelDomains(true); // Access the default source URIs $pslUri = DomainParser::getDefaultPublicSuffixListUri(); // => 'https://publicsuffix.org/list/public_suffix_list.dat' $tldUri = DomainParser::getDefaultTopLevelDomainListUri(); // => 'https://data.iana.org/TLD/tlds-alpha-by-domain.txt' ``` -------------------------------- ### Facade: `DomainParser` Source: https://context7.com/kevindierkx/laravel-domain-parser/llms.txt The `DomainParser` facade wraps the `akame\laravel\pdp\DomainParser` class, providing methods to retrieve cached PSL and TLD list instances. ```APIDOC ## Facade: `DomainParser` ### Description The `DomainParser` facade (`Bakame\Laravel\Pdp\Facades\DomainParser`) wraps the `\Bakame\Laravel\Pdp\DomainParser` class. It provides methods to retrieve the cached PSL and TLD list instances, with an optional `$fresh` flag to force-refresh the cache. ### Methods - **getRules(bool $fresh = false)**: Retrieves the cached PublicSuffixList instance. If `$fresh` is true, forces a cache refresh. - **getTopLevelDomains(bool $fresh = false)**: Retrieves the cached TopLevelDomainList instance. If `$fresh` is true, forces a cache refresh. - **getDefaultPublicSuffixListUri()**: Returns the default URI for the Public Suffix List. - **getDefaultTopLevelDomainListUri()**: Returns the default URI for the Top Level Domain list. ### Usage Example ```php use Bakame\Laravel\Pdp\Facades\DomainParser; // Get the cached PublicSuffixList instance $rules = DomainParser::getRules(); // Get a fresh (force-refreshed) PublicSuffixList instance $rules = DomainParser::getRules(true); // Get the cached TopLevelDomainList instance $tlds = DomainParser::getTopLevelDomains(); // Get a fresh TopLevelDomainList instance $tlds = DomainParser::getTopLevelDomains(true); // Access the default source URIs $pslUri = DomainParser::getDefaultPublicSuffixListUri(); // => 'https://publicsuffix.org/list/public_suffix_list.dat' $tldUri = DomainParser::getDefaultTopLevelDomainListUri(); // => 'https://data.iana.org/TLD/tlds-alpha-by-domain.txt' ``` ``` -------------------------------- ### TopLevelDomains Facade Source: https://context7.com/kevindierkx/laravel-domain-parser/llms.txt The `TopLevelDomains` facade provides access to the IANA Root Zone Database for TLD-based lookups. It proxies the `akameuzzy-domain-resolver ld TopLevelDomains` class. ```APIDOC ## Facade: `TopLevelDomains` The `TopLevelDomains` facade (`Bakame\Laravel\Pdp\Facades\TopLevelDomains`) proxies `\Pdp\TopLevelDomains` (the `TopLevelDomainList` instance), bound in the IoC container as `pdp.tld`. It provides access to the IANA Root Zone Database for TLD-based lookups. ```php use Bakame\Laravel\Pdp\Facades\TopLevelDomains; // Resolve a domain against the IANA TLD list $result = TopLevelDomains::resolve('www.example.com'); echo $result->suffix()->toString(); // => 'com' echo $result->suffix()->isKnown(); // => true // Iterate over all known TLDs foreach (TopLevelDomains::getIterator() as $tld) { echo $tld . PHP_EOL; // => 'COM', 'NET', 'ORG', ... } // IoC container alternative $tlds = app('pdp.tld'); $result = $tlds->resolve('mysite.io'); echo $result->suffix()->toString(); // => 'io' ``` ``` -------------------------------- ### Artisan Command: domain-parser:refresh Source: https://context7.com/kevindierkx/laravel-domain-parser/llms.txt Warms or refreshes the cached Public Suffix List and/or IANA TLD list. By default, both lists are refreshed. ```APIDOC ## Artisan Command: `domain-parser:refresh` ### Description Warms or refreshes the cached Public Suffix List and/or IANA TLD list. By default (no flags), both lists are refreshed. ### Usage ```bash # Refresh both lists (default) php artisan domain-parser:refresh # Refresh only the Public Suffix List php artisan domain-parser:refresh --rules # Refresh only the IANA Root Zone Database (TLD list) php artisan domain-parser:refresh --tlds ``` ### Scheduling Schedule the command in `app/Console/Kernel.php` to keep data current automatically: ```php // app/Console/Kernel.php protected function schedule(Schedule $schedule): void { // Refresh both lists every day at 04:00 $schedule->command('domain-parser:refresh')->daily()->at('04:00'); } ``` ``` -------------------------------- ### IoC Container Bindings for Domain Parsing Source: https://context7.com/kevindierkx/laravel-domain-parser/llms.txt Access domain parsing functionalities via Laravel's service container. The 'pdp.parser' singleton provides a DomainParser instance, 'pdp.rules' provides PublicSuffixList, and 'pdp.tld' provides TopLevelDomainList. ```php // pdp.parser — resolves the DomainParser helper instance $parser = app('pdp.parser'); $rules = $parser->getRules(); // Pdp\Rules (PublicSuffixList) $tlds = $parser->getTopLevelDomains(); // Pdp\TopLevelDomains // pdp.rules — resolves the PublicSuffixList directly $rules = app('pdp.rules'); $result = $rules->resolve('sub.example.co.uk'); // pdp.tld — resolves the TopLevelDomainList directly $tlds = app('pdp.tld'); $result = $tlds->resolve('example.io'); ``` -------------------------------- ### Refresh Both Data Sets Cache Source: https://github.com/kevindierkx/laravel-domain-parser/blob/master/docs/10-getting-started.md Manually update the cache for both the Public Suffix List and the IANA Root Zone Database using this Artisan command. This is the default behavior. ```bash php artisan domain-parser:refresh ``` -------------------------------- ### Update Namespace: Adapter to DomainParser Source: https://github.com/kevindierkx/laravel-domain-parser/blob/master/UPGRADING.md Replace the old Adapter class namespace with the new DomainParser class namespace. This change is necessary due to internal refactoring. ```diff suffix()->toString(); // => 'com' echo $result->suffix()->isKnown(); // => true // Iterate over all known TLDs foreach (TopLevelDomains::getIterator() as $tld) { echo $tld . PHP_EOL; // => 'COM', 'NET', 'ORG', ... } // IoC container alternative $tlds = app('pdp.tld'); $result = $tlds->resolve('mysite.io'); echo $result->suffix()->toString(); // => 'io' ``` -------------------------------- ### Schedule Domain Parser Refresh Command Source: https://context7.com/kevindierkx/laravel-domain-parser/llms.txt Schedule the `domain-parser:refresh` command in `app/Console/Kernel.php` to automatically keep PSL and TLD data up-to-date. ```php // app/Console/Kernel.php protected function schedule(Schedule $schedule): void { // Refresh both lists every day at 04:00 $schedule->command('domain-parser:refresh')->daily()->at('04:00'); } ``` -------------------------------- ### Artisan Command: Refresh Domain Parser Data Source: https://context7.com/kevindierkx/laravel-domain-parser/llms.txt Use the `domain-parser:refresh` Artisan command to refresh the cached Public Suffix List and/or IANA TLD list. Use flags to specify which list(s) to refresh. ```bash # Refresh both lists (default) php artisan domain-parser:refresh # Refresh only the Public Suffix List php artisan domain-parser:refresh --rules # Refresh only the IANA Root Zone Database (TLD list) php artisan domain-parser:refresh --tlds ``` -------------------------------- ### Refresh IANA Root Zone Database Cache Source: https://github.com/kevindierkx/laravel-domain-parser/blob/master/docs/10-getting-started.md Manually update the cache for the IANA Root Zone Database using this Artisan command. ```bash php artisan domain-parser:refresh --tlds ``` -------------------------------- ### Refresh Public Suffix List Cache Source: https://github.com/kevindierkx/laravel-domain-parser/blob/master/docs/10-getting-started.md Manually update the cache for the Public Suffix List using this Artisan command. ```bash php artisan domain-parser:refresh --rules ``` -------------------------------- ### Update Namespace: Refresh Cache Command Source: https://github.com/kevindierkx/laravel-domain-parser/blob/master/UPGRADING.md The namespace for the refresh cache command has been updated. Ensure you use the new path when referencing or calling the command. ```diff command('domain-parser:refresh')->daily()->at('04:00'); } ``` -------------------------------- ### Validate Domain Name Properties Source: https://github.com/kevindierkx/laravel-domain-parser/blob/master/docs/20-usage.md Use these validation rules to check if submitted values represent a valid domain name, TLD, or a domain with a known suffix. Ensure the validator instance is available. ```php $validator = Validator::make($request->all(), [ 'tld' => 'is_tld', 'domain' => 'is_icann_suffix', ]); ``` -------------------------------- ### Update Namespace: Facade Classes Source: https://github.com/kevindierkx/laravel-domain-parser/blob/master/UPGRADING.md Update the namespaces for facade classes to reflect the new structure. This ensures that Laravel can correctly resolve and use the facades. ```diff @domain_to_unicode($domain) ``` -------------------------------- ### Convert Domain Names in Blade Source: https://github.com/kevindierkx/laravel-domain-parser/blob/master/docs/20-usage.md Use these Blade directives to convert domain names to their Unicode or ASCII representations. This is useful for displaying internationalized domain names correctly. ```blade @domain_to_unicode('www.xn--85x722f.xn--55qx5d.cn') {{-- www.食狮.公司.cn --}} @domain_to_ascii('www.食狮.公司.cn') {{-- www.xn--85x722f.xn--55qx5d.cn --}} ``` -------------------------------- ### Blade Conditional Directives Source: https://context7.com/kevindierkx/laravel-domain-parser/llms.txt Six Blade `@if` directives allow domain checks directly in Blade templates. Each directive accepts a domain string and renders the `@else` branch when the condition is false. ```APIDOC ## Blade Conditional Directives (`@if`-style) Six Blade `@if` directives allow domain checks directly in Blade templates. Each directive accepts a domain string and renders the `@else` branch when the condition is false. | Directive | |---|---| | `@domain_name(...)` | True if value is a valid domain name | | `@tld(...)` | True if value is a known TLD | | `@contains_tld(...)` | True if value is a domain with a known TLD | | `@known_suffix(...)` | True if value is a domain with a known suffix | | `@icann_suffix(...)` | True if value is a domain with an ICANN suffix | | `@private_suffix(...)` | True if value is a domain with a private suffix | ```blade {{-- Check if a value is a valid domain name --}} @domain_name('www.example.com') Valid domain @else Invalid domain @enddomain_name {{-- Output: Valid domain --}} {{-- Check for a known TLD --}} @tld('com')
com is a known TLD
@endtld {{-- Output: com is a known TLD --}} {{-- Check that domain ends with a known TLD --}} @contains_tld('example.localhost')Has TLD
@elseNo known TLD
@endcontains_tld {{-- Output: No known TLD --}} {{-- Check for ICANN suffix --}} @icann_suffix('www.github.com')ICANN-registered suffix
@endicann_suffix {{-- Output: ICANN-registered suffix --}} {{-- Check for private suffix --}} @private_suffix('blogs.github.io')Private suffix detected
@endprivate_suffix {{-- Output: Private suffix detected --}} ``` ``` -------------------------------- ### Check Domain Name Properties in Blade Source: https://github.com/kevindierkx/laravel-domain-parser/blob/master/docs/20-usage.md Utilize these Blade conditionals to check if a given string is a domain name, contains a known TLD, or has a specific suffix. These directives simplify conditional rendering based on domain properties. ```blade @contains_tld('example.localhost') OK @else KO @endcontains_tld {{-- KO --}} ``` -------------------------------- ### Laravel Validator Rules for Domain Names Source: https://context7.com/kevindierkx/laravel-domain-parser/llms.txt Integrate custom validation rules for domain names directly into your Laravel application. These rules can be used in controllers or Form Request classes for validating TLDs, ICANN suffixes, private suffixes, and general domain name validity. ```php use Illuminate\Support\Facades\Validator; // --- In a controller --- $validator = Validator::make($request->all(), [ 'tld' => ['required', 'is_tld'], 'domain' => ['required', 'is_icann_suffix'], 'host' => ['required', 'is_domain_name'], 'private' => ['nullable', 'is_private_suffix'], ]); if ($validator->fails()) { // Default error messages: // 'tld' => 'The tld field is not a top level domain.' // 'domain' => 'The domain field is not a domain with an ICANN suffix.' // 'host' => 'The host field is not a valid domain name.' return back()->withErrors($validator); } // --- In a Form Request class --- class StoreDomainRequest extends FormRequest { public function rules(): array { return [ 'domain' => ['required', 'string', 'is_icann_suffix'], 'tld' => ['required', 'string', 'is_tld'], 'host' => ['required', 'string', 'contains_tld'], ]; } } // --- Standalone validation examples --- Validator::make(['domain' => 'example.com'], ['domain' => 'is_icann_suffix'])->passes(); // true Validator::make(['domain' => 'example.localhost'], ['domain' => 'contains_tld'])->passes(); // false Validator::make(['tld' => 'com'], ['tld' => 'is_tld'])->passes(); // true Validator::make(['tld' => 'invalidtld'], ['tld' => 'is_tld'])->passes(); // false Validator::make(['domain' => 'blogs.github.io'], ['domain' => 'is_private_suffix'])->passes(); // true ``` -------------------------------- ### Custom Validation Rules Source: https://context7.com/kevindierkx/laravel-domain-parser/llms.txt Six custom validation rules are registered for use with Laravel's `Validator`. These rules can be used in form request classes, controller validation, or directly with the `Validator` facade. ```APIDOC ## Validation Rules Six custom validation rules are registered for use with Laravel's `Validator`. They can be used in form request classes, controller validation, or directly with the `Validator` facade. | Rule | |---|---| | `is_domain_name` | Value must be a valid domain name (ICANN-resolvable) | | `is_tld` | Value must be a known IANA Top Level Domain | | `contains_tld` | Value must be a domain name ending with a known TLD | | `is_known_suffix` | Value must be a domain name with a known public suffix | | `is_icann_suffix` | Value must be a domain name with an ICANN-registered suffix | | `is_private_suffix` | Value must be a domain name with a private suffix | ```php use Illuminate\Support\Facades\Validator; // --- In a controller --- $validator = Validator::make($request->all(), [ 'tld' => ['required', 'is_tld'], 'domain' => ['required', 'is_icann_suffix'], 'host' => ['required', 'is_domain_name'], 'private' => ['nullable', 'is_private_suffix'], ]); if ($validator->fails()) { // Default error messages: // 'tld' => 'The tld field is not a top level domain.' // 'domain' => 'The domain field is not a domain with an ICANN suffix.' // 'host' => 'The host field is not a valid domain name.' return back()->withErrors($validator); } // --- In a Form Request class --- class StoreDomainRequest extends FormRequest { public function rules(): array { return [ 'domain' => ['required', 'string', 'is_icann_suffix'], 'tld' => ['required', 'string', 'is_tld'], 'host' => ['required', 'string', 'contains_tld'], ]; } } // --- Standalone validation examples --- Validator::make(['domain' => 'example.com'], ['domain' => 'is_icann_suffix'])->passes(); // true Validator::make(['domain' => 'example.localhost'], ['domain' => 'contains_tld'])->passes(); // false Validator::make(['tld' => 'com'], ['tld' => 'is_tld'])->passes(); // true Validator::make(['tld' => 'invalidtld'], ['tld' => 'is_tld'])->passes(); // false Validator::make(['domain' => 'blogs.github.io'], ['domain' => 'is_private_suffix'])->passes(); // true ``` ``` -------------------------------- ### Blade Directives for Domain Validation Source: https://context7.com/kevindierkx/laravel-domain-parser/llms.txt Utilize Blade conditional directives for domain name checks directly within your Blade templates. These directives simplify frontend validation logic by allowing checks for valid domain names, TLDs, and various suffix types. ```blade {{-- Check if a value is a valid domain name --}} @domain_name('www.example.com') Valid domain @else Invalid domain @enddomain_name {{-- Output: Valid domain --}} {{-- Check for a known TLD --}} @tld('com')com is a known TLD
@endtld {{-- Output: com is a known TLD --}} {{-- Check that domain ends with a known TLD --}} @contains_tld('example.localhost')Has TLD
@elseNo known TLD
@endcontains_tld {{-- Output: No known TLD --}} {{-- Check for ICANN suffix --}} @icann_suffix('www.github.com')ICANN-registered suffix
@endicann_suffix {{-- Output: ICANN-registered suffix --}} {{-- Check for private suffix --}} @private_suffix('blogs.github.io')Private suffix detected
@endprivate_suffix {{-- Output: Private suffix detected --}} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.