mirror of
https://github.com/coollabsio/coolify.git
synced 2026-10-06 05:58:14 -04:00
Add indexing, redirect, and hostname regeneration controls to domain editors. Queue DNS checks only for scheme or hostname changes and show progress consistently across application, service, and preview domains.
66 lines
2.0 KiB
PHP
66 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Support;
|
|
|
|
class DomainUrlParts
|
|
{
|
|
public static function compose(string $scheme, string $host, ?string $port = '', string $path = ''): string
|
|
{
|
|
$scheme = strtolower(trim($scheme)) === 'http' ? 'http' : 'https';
|
|
$host = trim($host);
|
|
$port = trim((string) $port);
|
|
$path = trim($path);
|
|
|
|
if ($path !== '' && ! str_starts_with($path, '/') && ! str_starts_with($path, '?') && ! str_starts_with($path, '#')) {
|
|
$path = '/'.$path;
|
|
}
|
|
|
|
return $scheme.'://'.$host.($port !== '' ? ':'.$port : '').$path;
|
|
}
|
|
|
|
/**
|
|
* @return array{scheme: string, host: string, port: string, path: string}
|
|
*/
|
|
public static function split(?string $url): array
|
|
{
|
|
$parts = filled($url) ? parse_url($url) : false;
|
|
if (! is_array($parts) || blank($parts['host'] ?? null)) {
|
|
return self::empty();
|
|
}
|
|
|
|
$path = $parts['path'] ?? '';
|
|
if (isset($parts['query'])) {
|
|
$path .= '?'.$parts['query'];
|
|
}
|
|
if (isset($parts['fragment'])) {
|
|
$path .= '#'.$parts['fragment'];
|
|
}
|
|
|
|
return [
|
|
'scheme' => in_array(strtolower($parts['scheme'] ?? ''), ['http', 'https'], true)
|
|
? strtolower($parts['scheme'])
|
|
: 'https',
|
|
'host' => (string) $parts['host'],
|
|
'port' => isset($parts['port']) ? (string) $parts['port'] : '',
|
|
'path' => $path,
|
|
];
|
|
}
|
|
|
|
public static function hasDnsRelevantChange(string $oldUrl, string $newUrl): bool
|
|
{
|
|
$old = self::split($oldUrl);
|
|
$new = self::split($newUrl);
|
|
|
|
return $old['scheme'] !== $new['scheme']
|
|
|| strtolower($old['host']) !== strtolower($new['host']);
|
|
}
|
|
|
|
/**
|
|
* @return array{scheme: string, host: string, port: string, path: string}
|
|
*/
|
|
public static function empty(): array
|
|
{
|
|
return ['scheme' => 'https', 'host' => '', 'port' => '', 'path' => ''];
|
|
}
|
|
}
|