From 76d8f833040996fa32bb6c3f961468f0e342ea6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Fri, 15 Mar 2024 16:14:05 +0100 Subject: [PATCH] use http_client() from castor --- .castor/docker.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.castor/docker.php b/.castor/docker.php index 7505789..8c1143f 100644 --- a/.castor/docker.php +++ b/.castor/docker.php @@ -6,6 +6,7 @@ use Castor\Attribute\AsOption; use Castor\Attribute\AsTask; use Castor\Context; +use Symfony\Contracts\HttpClient\Exception\ExceptionInterface as HttpExceptionInterface; use Symfony\Component\Process\Exception\ExceptionInterface; use Symfony\Component\Process\ExecutableFinder; use Symfony\Component\Process\Process; @@ -15,6 +16,7 @@ use function Castor\context; use function Castor\finder; use function Castor\fs; +use function Castor\http_client; use function Castor\io; use function Castor\log; use function Castor\open; @@ -33,9 +35,11 @@ function about(): void io()->section('Available URLs for this project:'); $urls = [variable('root_domain'), ...variable('extra_domains')]; - $payload = @file_get_contents(sprintf('http://%s:8080/api/http/routers', variable('root_domain'))); - if ($payload) { - $routers = json_decode($payload, true); + try { + $routers = http_client() + ->request('GET', sprintf('http://%s:8080/api/http/routers', variable('root_domain'))) + ->toArray() + ; $projectName = variable('project_name'); foreach ($routers as $router) { if (!preg_match("{^{$projectName}-(.*)@docker$}", $router['name'])) { @@ -50,7 +54,9 @@ function about(): void $hosts = explode('`) || Host(`', $matches['hosts']); $urls = [...$urls, ...$hosts]; } + } catch (HttpExceptionInterface) { } + io()->listing(array_map(fn ($url) => "https://{$url}", array_unique($urls))); }