coolify/app/View/Components/Services/Links.php
Andras Bacsai 67078fdc71 wip: services
feat: able to map port<->domain
2023-09-22 14:47:25 +02:00

47 lines
1.4 KiB
PHP

<?php
namespace App\View\Components\Services;
use App\Models\Service;
use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Collection;
use Illuminate\View\Component;
use Illuminate\Support\Str;
class Links extends Component
{
public Collection $links;
public function __construct(public Service $service)
{
$this->links = collect([]);
$service->applications()->get()->map(function ($application) {
if ($application->fqdn) {
$fqdns = collect(Str::of($application->fqdn)->explode(','));
$fqdns->map(function ($fqdn) {
$this->links->push(getOnlyFqdn($fqdn));
});
}
if ($application->ports) {
$portsCollection = collect(Str::of($application->ports)->explode(','));
$portsCollection->map(function ($port) {
if (Str::of($port)->contains(':')) {
$hostPort = Str::of($port)->before(':');
} else {
$hostPort = $port;
}
$this->links->push(base_url(withPort:false) . ":{$hostPort}");
});
}
});
}
/**
* Get the view / contents that represent the component.
*/
public function render(): View|Closure|string
{
return view('components.services.links');
}
}