2019-11-27 22:19:20 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Support;
|
|
|
|
|
2019-12-13 04:07:35 +08:00
|
|
|
use Illuminate\Contracts\Container\BindingResolutionException;
|
2020-01-29 01:42:46 +08:00
|
|
|
use Illuminate\Support\Str;
|
2019-11-27 22:19:20 +08:00
|
|
|
use Nwidart\Modules\Facades\Module;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Global utilities
|
|
|
|
*/
|
|
|
|
class Utils
|
|
|
|
{
|
2019-12-13 04:07:35 +08:00
|
|
|
/**
|
|
|
|
* Enable the debug toolbar
|
|
|
|
*/
|
|
|
|
public static function enableDebugToolbar()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
app('debugbar')->enable();
|
|
|
|
} catch (BindingResolutionException $e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disable the debug toolbar
|
|
|
|
*/
|
|
|
|
public static function disableDebugToolbar()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
app('debugbar')->disable();
|
|
|
|
} catch (BindingResolutionException $e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-27 22:19:20 +08:00
|
|
|
/**
|
|
|
|
* Is the installer enabled?
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function installerEnabled()
|
|
|
|
{
|
|
|
|
/** @var \Nwidart\Modules\Module $installer */
|
|
|
|
$installer = Module::find('installer');
|
|
|
|
if (!$installer) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $installer->isEnabled();
|
|
|
|
}
|
2020-01-29 01:42:46 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the domain from a URL
|
|
|
|
*
|
|
|
|
* @param string $url
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function getRootDomain(string $url): string
|
|
|
|
{
|
|
|
|
if (!Str::contains($url, ['https://', 'http://'])) {
|
|
|
|
$url = 'http://'.$url;
|
|
|
|
}
|
|
|
|
|
|
|
|
$domain = parse_url($url, PHP_URL_HOST);
|
|
|
|
$domain = explode('.', $domain);
|
|
|
|
$len = count($domain);
|
|
|
|
if ($len == 1) {
|
|
|
|
return $domain[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
$domain = $domain[$len - 2].'.'.$domain[$len - 1];
|
|
|
|
|
|
|
|
return $domain;
|
|
|
|
}
|
2019-11-27 22:19:20 +08:00
|
|
|
}
|