1
0
Fork 0
mirror of https://github.com/Yetangitu/ampache synced 2025-10-04 02:09:23 +02:00

Add XBMC Localplay

This commit is contained in:
Afterster 2013-11-02 15:17:34 +01:00 committed by Paul Arthur
parent 872012a24f
commit 539ca08efc
18 changed files with 1703 additions and 0 deletions

View file

@ -0,0 +1,66 @@
<?php
class XBMC_RPC_Response {
/**
* @var string The id of the response as returned from the server.
* @access private
*/
private $id;
/**
* @var string The data returned from the server if the response was successful.
* @access private
*/
private $data;
/**
* Constructor.
*
* @param string $response The JSON-decoded response string
* as returned from the server
*/
public function __construct($response) {
$response = $this->decodeResponse($response);
$this->id = $response['id'];
if (isset($response['error'])) {
throw new XBMC_RPC_ResponseException($response['error']['message'], $response['error']['code']);
} elseif (!isset($response['result'])) {
throw new XBMC_RPC_ResponseException('Invalid JSON RPC response');
}
$this->data = $response['result'];
}
/**
* Gets the response data.
*
* @return mixed The response data.
*/
public function getData() {
return $this->data;
}
/**
* Gets the response id.
*
* @return string The response id.
*/
public function getId() {
return $this->id;
}
/**
* Takes a JSON string as returned from the server and decodes it into an
* associative array.
*/
private function decodeResponse($json) {
if (extension_loaded('mbstring')) {
$encoding = mb_detect_encoding($json, 'ASCII,UTF-8,ISO-8859-1,windows-1252,iso-8859-15');
if ($encoding && !in_array($encoding, array('UTF-8', 'ASCII'))) {
$json = mb_convert_encoding($json, 'UTF-8', $encoding);
}
}
return json_decode($json, true);
}
}