8000 GitHub - rincler/domain at 3.0.2
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
/ domain Public

A domain name value object. Works with IDN and punycode syntax, validates and easily retrieves the level, zone and TLD (top-level domain).

License

Notifications You must be signed in to change notification settings

rincler/domain

Repository files navigation

Domain

Packagist Version Build Status PHP from Packagist (specify version)

Domain name value object

Usage

<?php

use \Rincler\Domain\Domain;

$domain = new Domain('sub.domain.com');
echo $domain; // sub.domain.com
echo $domain->asIdn(); // sub.domain.com
echo $domain->asPunycode(); // sub.domain.com
echo $domain->getZone(); // domain.com
echo $domain->getWithoutZone(); // sub
echo $domain->getTld(); // com
echo $domain->getWithoutTld(); // sub.domain
echo $domain->getLevel(); // 3

$domain = new Domain('домен.рф');
echo $domain->asIdn(); // домен.рф
echo $domain->asPunycode(); // xn--d1acufc.xn--p1ai

$domain = new Domain('xn--d1acufc.xn--p1ai');
echo $domain->asIdn(); // домен.рф
echo $domain->asPunycode(); // xn--d1acufc.xnn

Installation

composer require rincler/domain

Documentation

  • static isValid(): bool - Returns true if domain is valid, returns false otherwise
  • __constructor(string $domain) - The constructor validates domain (throws InvalidDomainException if domain is not valid) and creates object of domain
  • asIdn(): string - Returns domain as IDN string
  • asPunycode(): string - Returns domain as Punycode string
  • getLevel(): int - Returns domain levels count
  • getZone(): Domain - Returns zone of domain
  • getWithoutZone(): Domain - Returns domain without zone
  • getTld(): Domain - Returns top-level domain
  • getWithoutTld(): Domain - Returns domain without top-level domain
  • equals(Domain $domain): bool - Returns true if current domain equals checked domain, returns false otherwise
  • __toString(): string - Analog for getIdn

Why PHP >= 7.3?

Validation of domain in intl extension fixed in 7.3.0. See http://bugs.php.net/76829

License

This library is released under the MIT license.

About

A domain name value object. Works with IDN and punycode syntax, validates and easily retrieves the level, zone and TLD (top-level domain).

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages

0