Update to Laravel 8 (#1058)

* Update Laravel and other dependencies

* Composer version in CI

* Remove the PHP exit from env file

* Add PHP 8 to testing matrix

* Update doctrine

* Update doctrine

* Update faker lib

* Rewrite TLD check to remove deprecated library

* Update version lib

* Remove PHP 8 for now

* Style fixes
This commit is contained in:
Nabeel S
2021-03-04 17:08:51 -05:00
committed by GitHub
parent 922e754c9e
commit 3800c01d94
12 changed files with 15491 additions and 900 deletions

View File

@@ -5,9 +5,8 @@ namespace App\Support;
use App\Contracts\Model;
use Hashids\Hashids;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Support\Str;
use LayerShifter\TLDExtract\Extract;
use Nwidart\Modules\Facades\Module;
use Pdp\Rules;
/**
* Global utilities
@@ -110,26 +109,36 @@ class Utils
*/
public static function getRootDomain(string $url): string
{
if (Str::contains($url, ['https://', 'http://'])) {
$url = str_replace('https://', '', $url);
$url = str_replace('http://', '', $url);
if (!str_starts_with($url, 'http')) {
$url = 'http://'.$url;
}
$extract = new Extract();
$result = $extract->parse($url);
$parsed_url = parse_url($url, PHP_URL_HOST);
if (empty($parsed_url)) {
return '';
}
$val = $result->getRegistrableDomain();
if (str_ends_with($parsed_url, 'localhost')) {
return 'localhost';
}
if (str_ends_with($parsed_url, '/')) {
$parsed_url = substr($parsed_url, 0, strlen($parsed_url) - 1);
}
$rules = Rules::createFromPath(resource_path('tld/public_suffix_list.dat'));
$domain = $rules->resolve($parsed_url);
$val = $domain->getRegistrableDomain();
if (!empty($val)) {
return $val;
}
if ($result->hostname === 'localhost') {
return 'localhost';
// Couldn't validate a domain, see if this is an IP address?
if (filter_var($parsed_url, FILTER_VALIDATE_IP)) {
return $parsed_url;
}
// Couldn't validate a domain, see if this is an IP address?
if (filter_var($url, FILTER_VALIDATE_IP)) {
return $url;
}
return '';
}
}