lasthourcloud/app/View/Components/Services/Links.php

56 lines
1.8 KiB
PHP
Raw Normal View History

2023-09-22 09:23:49 +00:00
<?php
namespace App\View\Components\Services;
use App\Models\Service;
use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Collection;
2024-06-10 20:43:34 +00:00
use Illuminate\View\Component;
2023-09-22 09:23:49 +00:00
class Links extends Component
{
public Collection $links;
2024-06-10 20:43:34 +00:00
2023-09-22 09:23:49 +00:00
public function __construct(public Service $service)
{
$this->links = collect([]);
$service->applications()->get()->map(function ($application) {
$type = $application->serviceType();
if ($type) {
$links = generateServiceSpecificFqdns($application);
$links = $links->map(function ($link) {
return getFqdnWithoutPort($link);
});
$this->links = $this->links->merge($links);
} else {
if ($application->fqdn) {
$fqdns = collect(str($application->fqdn)->explode(','));
$fqdns->map(function ($fqdn) {
$this->links->push(getFqdnWithoutPort($fqdn));
});
}
if ($application->ports) {
$portsCollection = collect(str($application->ports)->explode(','));
$portsCollection->map(function ($port) {
if (str($port)->contains(':')) {
$hostPort = str($port)->before(':');
} else {
$hostPort = $port;
}
2024-06-10 20:43:34 +00:00
$this->links->push(base_url(withPort: false).":{$hostPort}");
});
}
}
2023-09-22 09:23:49 +00:00
});
}
/**
* Get the view / contents that represent the component.
*/
public function render(): View|Closure|string
{
return view('components.services.links');
}
}