bakame/laravel-domain-parser

Laravel package to integrate PHP Domain parser.

0.4.0 2020-09-08 14:03 UTC

This package is auto-updated.

Last update: 2020-10-14 13:03:38 UTC


README

Latest Version Software License Build Status Scrutinizer Code Coverage

A Laravel package to ease PHP Domain Parser integration in your Laravel application.

Version Compatibility

Laravel Package
5.x >= 0.3
6.x >= 0.4
7.x >= 0.4

Installation

Install the package via composer:

$ composer require kevindierkx/laravel-domain-parser

This package implements Laravel's Package Discovery, no further changes are needed to your application configs. For more information please refer to the Laravel documentation.

Configuration

In order to edit the default configuration you need to publish the package configuration to your application config directory:

php artisan vendor:publish --provider="Bakame\Laravel\Pdp\ServiceProvider" --tag=config

The config file will be published in config/domain-parser.php. Please refer to the config file for an overview of the available options.

Usage

The package provides some useful Laravel implementations in the form of validation rules, Blade directives and Blade conditionals. Additionally it provides a bridge with the PHP Domain Parser base package, please refer to the documentation for an overview of all functionality.

Please note: By default the Rules and TopLevelDomains facades will be registered during package discovery. In the following examples we will use these facades directly.

Validation rules

Rules Description
is_domain_name Tells whether the submitted value represents a Domain Name
is_tld Tells whether the submitted value is a TLD
contains_tld Tells whether the submitted value is a Domain Name with a known TLD
is_known_suffix Tells whether the submitted value is a Domain Name with a known suffix
is_icann_suffix Tells whether the submitted value is a Domain Name with an ICANN suffix
is_private_suffix Tells whether the submitted value is a Domain Name with a Private suffix
$validator = Validator::make($request->all(), [
    'tld' => 'is_tld',
    'domain' => 'is_icann_suffix',
]);

Blade if statement directives

If statement Description
domain_name Tells whether the submitted value represents a Domain Name
tld Tells whether the submitted value is a TLD
contains_tld Tells whether the submitted value is a Domain Name with a known TLD
known_suffix Tells whether the submitted value is a Domain Name with a Known suffix
icann_suffix Tells whether the submitted value is a Domain Name with an ICANN suffix
private_suffix Tells whether the submitted value is a Domain Name with a Private suffix
@contains_tld('example.localhost')
OK
@else
KO
@endcontains_tld
{{-- KO --}}

Blade directives

directive Description
domain_to_unicode Converts the hostname into its Unicode representation
domain_to_ascii Converts the hostname into its Ascii representation
@domain_to_unicode('www.xn--85x722f.xn--55qx5d.cn') {{-- www.食狮.公司.cn --}}
@domain_to_ascii('www.食狮.公司.cn') {{-- www.xn--85x722f.xn--55qx5d.cn --}}

Facades

  • Rules is a Laravel Facade for Pdp\Rules loaded using the configuration files settings.
$domain = Rules::resolve('www.ulb.ac.be'); //$domain is a Pdp\Domain object
echo $domain->getContent();            // 'www.ulb.ac.be'
echo $domain->getPublicSuffix();       // 'ac.be'
echo $domain->getRegistrableDomain();  // 'ulb.ac.be'
echo $domain->getSubDomain();          // 'www'
$domain->isResolvable();               // returns true
$domain->isKnown();                    // returns true
$domain->isICANN();                    // returns true
$domain->isPrivate();                  // returns false
  • TopLevelDomains is a Laravel Facade for Pdp\TopLevelDomains loaded using the configuration files settings.
TopLevelDomains::contains('localhost'); // return false

Maintenance

Refresh Cache Command

You can warm and/or update the cache information using the bundled refresh cache command manually.

You can choose to refresh:

  • The Public Suffix List
php artisan domain-parser:refresh --rules
  • The IANA Root Zone Database
php artisan domain-parser:refresh --tlds
  • Both data sets in a single call (default)
php artisan domain-parser:refresh

Scheduling

It is recommended to schedule the refresh command so you don't have to manually run domain-parser:refresh every time you need to update your cache.

The command can be scheduled in Laravel's console kernel, just like any other command.

// app/Console/Kernel.php
protected function schedule(Schedule $schedule)
{
   $schedule->command('domain-parser:refresh')->daily()->at('04:00');
}

Changelog

Please see CHANGELOG for more information on what has changed recently.

Testing

To run the tests, run the following command from the project folder:

$ composer test

Security

If you discover a security vulnerability within this package, please send an e-mail to Kevin Dierkx via kevin@distortedfusion.com. All security vulnerabilities will be promptly addressed.

Contributing

Contributions are welcome and will be fully credited. Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.