Skip to content

Commit

Permalink
Allow FQDN parsing with full urls
Browse files Browse the repository at this point in the history
  • Loading branch information
bajb committed Feb 12, 2015
1 parent 442ac2a commit 1326282
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/FQDN.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public function __construct($fqdn)

public function setFqdn($fqdn)
{
if(filter_var($fqdn, FILTER_VALIDATE_URL))
{
$fqdn = parse_url($fqdn, 1);
}
$this->_fqdn = strtolower($fqdn);
$this->_domain = $this->_subdomain = $this->_tld = null;
$this->_processed = false;
Expand Down
8 changes: 8 additions & 0 deletions tests/FQDNTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,12 @@ public function testDefinedTlds()

$this->assertEquals(['random.tld'], $fq->getDefinedTlds());
}

public function testUrl()
{
$fq = new \Packaged\Helpers\FQDN('http://my.test.co.uk/webpage.html');
$this->assertEquals("test", $fq->domain());
$this->assertEquals("co.uk", $fq->tld());
$this->assertEquals("my", $fq->subDomain());
}
}

0 comments on commit 1326282

Please sign in to comment.