Ticket #9939: meta-bindings.diff

File meta-bindings.diff, 1.5 KB (added by Doug Haber <doug@…>, 13 years ago)

Minor changes to php bindings for getting JSON data from backend calls

  • mythtv/bindings/php/MythBackend.php

    diff --git a/mythtv/bindings/php/MythBackend.php b/mythtv/bindings/php/MythBackend.php
    index 16781e8..8446984 100644
    a b class MythBackend { 
    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}