protected function setUp() { parent::setUp(); $pslManager = new PublicSuffixListManager(dirname(dirname(dirname(__DIR__))) . '/data'); $pslParser = new PslParser($pslManager->getList()); $this->parser = new Parser($pslParser); }
public static function instance() { if (static::$instance === null) { $list = new PublicSuffixListManager(); static::$instance = new SwotImpl(new Parser($list->getList())); } return static::$instance; }
/** * Wrapper around Jeremy Kendall's PHP Domain Parser that parses the * domain/url passed to the function and returns the Tld and Valid domain * @param $domain * @throws \InvalidArgumentException when the tld is not valid * @return array returns an associative array with the domain and tld */ private function parse($domain) { $pslManager = new PublicSuffixListManager(); $parser = new Parser($pslManager->getList()); // First check if the suffix is actually valid if (!$parser->isSuffixValid($domain)) { throw new \InvalidArgumentException("Invalid TLD"); } $components = []; $components["tld"] = $parser->getPublicSuffix($domain); $components["domain"] = $parser->getRegisterableDomain($domain); return $components; }
/** * Register bindings in the container. * * @return void */ public function register() { $this->app->bind('guzzle', function () { return new Client(['connect_timeout' => 3, 'timeout' => 10]); }); $this->app->bind('pdp', function () { $pslManager = new PublicSuffixListManager(); $parser = new Parser($pslManager->getList()); return $parser; }); $this->app->bind('oembed', function () { return new OEmbed(); }); }
/** * @return string|null */ public function getDomain() { if (!isset($this->uri['host'])) { return null; } $pslManager = new PublicSuffixListManager(); $parser = new Parser($pslManager->getList()); $parse = $parser->parseUrl($this->uri['host'] . '://' . $this->uri['host']); return $parse->host->registerableDomain; }
public function setUp() { $list = new PublicSuffixListManager(); $this->swot = new Swot(new Parser($list->getList())); }
public function testGetProvidedListFromDefaultCacheDir() { // By not providing cache I'm forcing use of default cache dir $listManager = new PublicSuffixListManager(); $publicSuffixList = $listManager->getList(); $this->assertInstanceOf('\\Pdp\\PublicSuffixList', $publicSuffixList); $this->assertGreaterThanOrEqual(300, count($publicSuffixList)); $this->assertTrue(array_key_exists('stuff-4-sale', $publicSuffixList['org']) !== false); $this->assertTrue(array_key_exists('net', $publicSuffixList['ac']) !== false); }
/** * @param bool $withSuffix * * @return null|string */ public function getDomain(bool $withSuffix = true) { if (!isset($this->uri['host'])) { return null; } $pslManager = new PublicSuffixListManager(); $parser = new Parser($pslManager->getList()); $parse = $parser->parseUrl($this->uri['host'] . '://' . $this->uri['host']); if ($withSuffix) { return $parse->host->registerableDomain; } else { return substr($parse->host->registerableDomain, 0, -strlen($parse->host->publicSuffix) - 1); } }
public function getLiveDns($hostname) { $pslManager = new PublicSuffixListManager(); $domainParser = new Parser($pslManager->getList()); $hostname = strtolower($hostname); $baseDomain = $domainParser->getRegisterableDomain($hostname); $ipUtils = $this->ipUtils; $records = Cache::remember($hostname, 60 * 24, function () use($ipUtils, $hostname) { $dns = new Dns(['8.8.8.8', '8.8.4.4', 2]); $records = $dns->getDomainRecords($hostname, $testNameserver = false); ksort($records); if (isset($records['A']) === true) { $records['A'] = array_unique($records['A']); foreach ($records['A'] as $key => $address) { $geoip = $ipUtils->geoip($address); if ($geoip->country->isoCode) { $country_code = $geoip->country->isoCode; $country_name = $geoip->country->name; $city_name = $geoip->city->name; } else { $ipDec = $this->ipUtils->ip2dec($address); $prefix = IPv4BgpPrefix::where('ip_dec_start', '<=', $ipDec)->where('ip_dec_end', '>=', $ipDec)->orderBy('cidr', 'asc')->first(); if ($prefix && ($prefixWhois = $prefix->whois())) { $country_code = $prefixWhois->counrty_code; $country_name = $prefixWhois->counrty_code ? trans('countries.' . $prefixWhois->counrty_code) : null; $city_name = null; } else { $country_code = null; $country_name = 'Unknown'; $city_name = null; } } $output['address'] = $address; $output['country_code'] = $country_code; if ($city_name) { $output['location'] = $city_name . ', ' . $country_name; } else { $output['location'] = $country_name; } $records['A'][$key] = $output; } } if (isset($records['AAAA']) === true) { $records['AAAA'] = array_unique($records['AAAA']); foreach ($records['AAAA'] as $key => $address) { $geoip = $ipUtils->geoip($address); if ($geoip->country->isoCode) { $country_code = $geoip->country->isoCode; $country_name = $geoip->country->name; $city_name = $geoip->city->name; } else { $ipDec = $this->ipUtils->ip2dec($address); $prefix = IPv6BgpPrefix::where('ip_dec_start', '<=', $ipDec)->where('ip_dec_end', '>=', $ipDec)->orderBy('cidr', 'asc')->first(); if ($prefix && ($prefixWhois = $prefix->whois())) { $country_code = $prefixWhois->counrty_code; $country_name = $prefixWhois->counrty_code ? trans('countries.' . $prefixWhois->counrty_code) : null; $city_name = null; } else { $country_code = null; $country_name = 'Unknown'; $city_name = null; } } $output['address'] = $address; $output['country_code'] = $country_code; if ($city_name) { $output['location'] = $city_name . ', ' . $country_name; } else { $output['location'] = $country_name; } $records['AAAA'][$key] = $output; } } return $records; }); $data['hostname'] = $hostname; $data['base_domain'] = $baseDomain; $data['dns_records'] = $records; return $this->sendData($data); }
/** * Creates the default Parser instance to parse urls. * * @return Parser */ private static function createDefaultParser() { $pslManager = new PublicSuffixListManager(dirname(dirname(__DIR__)) . '/data'); $pslParser = new PslParser($pslManager->getList()); return new Parser($pslParser); }
<?php require_once __DIR__ . '/vendor/autoload.php'; use Pdp\PublicSuffixListManager; use Pdp\Parser; // Obtain an instance of the parser $pslManager = new PublicSuffixListManager(); $parser = new Parser($pslManager->getList()); // Parse a URL $url = $parser->parseUrl('http://*****:*****@www.pref.okinawa.jp:8080/path/to/page.html?query=string#fragment'); // Accessing elements of the URL var_dump($url); var_dump($url->__toString()); var_dump($url->getPath()); var_dump($url->getFragment()); // Getting the Host object from the URL $host = $url->getHost(); // Accessing elements of the Host var_dump($host); var_dump($host->__toString()); var_dump($host->getSubdomain()); var_dump($host->getRegistrableDomain()); var_dump($host->getPublicSuffix()); // It's possible to parse a host only, if you prefer $host = $parser->parseHost('a.b.c.cy'); // Accessing elements of the Host var_dump($host); var_dump($host->__toString()); var_dump($host->getSubdomain()); var_dump($host->getRegistrableDomain()); var_dump($host->getPublicSuffix());
/** * Get the fully qualified naked domain name. * * @param Buzz\Message\Request $request * @return string */ protected function getDomain($request) { if ($host = filter_var($this->metadata['host'], FILTER_VALIDATE_IP)) { return $host; } $manager = new PublicSuffixListManager(); $parser = new DomainParser($manager->getList()); return $parser->parseUrl($this->metadata['url'])->host->registerableDomain; }