Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for http endpoint in addition to the websocket #599

Open
wants to merge 7 commits into
base: 1.11
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/Communication/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,30 @@ public function __construct($socketClient, LoggerInterface $logger = null, int $

// create socket client
if (\is_string($socketClient)) {

if (\in_array(\parse_url($socketClient, PHP_URL_SCHEME), ['http', 'https'])) {

$configURL = $socketClient.'/json/version';

$resp = \file_get_contents($configURL);
Copy link
Member

@GrahamCampbell GrahamCampbell Jan 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't call this without doing any error handling (yes, I really do mean "error" in the PHP 5 sense of the word).


if (false === $resp) {
throw new \Exception("Unable to request $configURL");
}

$json_resp = \json_decode($resp);
if (null === $json_resp) {
throw new \Exception("Invalid JSON response from $configURL");
}

if (!\property_exists($json_resp, 'webSocketDebuggerUrl')) {
throw new \Exception("Websocket debugger URL not found in response from $configURL");
}

$socketClient = $json_resp->webSocketDebuggerUrl;

}

$socketClient = new Wrench(new WrenchBaseClient($socketClient, 'http://127.0.0.1'), $this->logger);
} elseif (!\is_object($socketClient) && !$socketClient instanceof SocketInterface) {
throw new \InvalidArgumentException('$socketClient param should be either a SockInterface instance or a web socket uri string');
Expand Down