Skip to content

Commit 2631935

Browse files
author
Robert McNamara
committed
Minor PHP bindings updates needed for Mythweb metadata lookup.
Refs #9939 with a patch from Doug Haber.
1 parent bc9837f commit 2631935

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

mythtv/bindings/php/MythBackend.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,44 @@ public function rescheduleRecording($recordid = -1) {
212212
return false;
213213
}
214214

215+
216+
/**
217+
* Request something from the backend's HTTP API and return it
218+
* as JSON. This is just syntactic sugar for httpRequest
219+
/**/
220+
public function httpRequestAsJson($path, $args = array(), $opts = null) {
221+
if (!$opts) {
222+
$opts = array();
223+
}
224+
225+
if (!$opts['http']) {
226+
$opts['http'] = array();
227+
}
228+
229+
if (!$opts['http']['method']) {
230+
$opts['http']['method'] = "GET";
231+
}
232+
233+
$opts['http']['header'] = "Accept: application/json\r\n";
234+
235+
return $this->httpRequest($path, $args, $opts);
236+
}
237+
215238
/**
216239
* Request something from the backend's HTTP API
217240
/**/
218-
public function httpRequest($path, $args = array()) {
241+
public function httpRequest($path, $args = array(), $opts = null) {
219242
$url = "http://{$this->ip}:{$this->port_http}/{$path}?";
220243
foreach ($args as $key => $value) {
221244
$url .= urlencode($key).'='.urlencode($value).'&';
222245
}
223-
return @file_get_contents($url);
246+
247+
if (!$opts) {
248+
return @file_get_contents($url);
249+
} else {
250+
$context = stream_context_create($opts);
251+
return @file_get_contents($url, false, $context);
252+
}
224253
}
225254

226255
}

0 commit comments

Comments
 (0)