-
Notifications
You must be signed in to change notification settings - Fork 280
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
Changes from 1 commit
1e7e10c
068989d
567ce3a
24353f6
6ec7c33
ceeb576
ce246d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,6 +106,41 @@ public function __construct($socketClient, LoggerInterface $logger = null, int $ | |
|
||
// create socket client | ||
if (\is_string($socketClient)) { | ||
|
||
$parsedUrl = parse_url($socketClient); | ||
if (isset($parsedUrl['scheme']) && ($parsedUrl['scheme']==='http' or $parsedUrl['scheme']==='https')) | ||
{ | ||
|
||
$configURL = $socketClient.'/json/version'; | ||
|
||
$curl = curl_init($configURL); | ||
curl_setopt($curl, CURLOPT_URL, $configURL); | ||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | ||
$resp = curl_exec($curl); | ||
|
||
if ($resp === false) { | ||
$err = curl_error($curl); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why get the error if we are not using it for anything? |
||
curl_close($curl); | ||
|
||
throw new \Exception("Unable to request $configURL"); | ||
} | ||
else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This else isn't doing anything. The throw in the previous if will stop the execution on this method. |
||
curl_close($curl); | ||
} | ||
|
||
$json_resp = json_decode($resp); | ||
if (is_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'); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The expression could be simpler:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please always use strict mode, unless you have a very good reason to not do it - it's less important in modern php, but in <=7.4: https://3v4l.org/Yc3UU