mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-04 02:09:23 +02:00
Add XBMC Localplay
This commit is contained in:
parent
872012a24f
commit
539ca08efc
18 changed files with 1703 additions and 0 deletions
88
modules/xbmc-php-rpc/Server.php
Normal file
88
modules/xbmc-php-rpc/Server.php
Normal file
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
require_once 'ServerException.php';
|
||||
|
||||
class XBMC_RPC_Server {
|
||||
|
||||
/**
|
||||
* @var mixed An array of parameters used to connect to the server.
|
||||
* @access private
|
||||
*/
|
||||
private $parameters = array();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param mixed $parameters An associative array of connection parameters,
|
||||
* or a valid connection URI as a string. If supplying an array, the following
|
||||
* paramters are accepted: host, port, user and pass. Any other parameters
|
||||
* are discarded.
|
||||
* @exception XBMC_RPC_ServerException if the supplied parameters could not
|
||||
* be parsed successfully.
|
||||
* @access public
|
||||
*/
|
||||
public function __construct($parameters) {
|
||||
if (!$parameters = $this->parseParameters($parameters)) {
|
||||
throw new XBMC_RPC_ServerException('Unable to parse server parameters');
|
||||
}
|
||||
$this->parameters = $parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the server is connected.
|
||||
*
|
||||
* @return bool True if the server is connected, false if not.
|
||||
* @access public
|
||||
*/
|
||||
public function isConnected() {
|
||||
return $this->connected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the connection parameters/
|
||||
*
|
||||
* @return mixed The connection parameters as an associative array.
|
||||
* @access public
|
||||
*/
|
||||
public function getParameters() {
|
||||
return $this->parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the supplied parameters into a standard associative array format.
|
||||
*
|
||||
* @param mixed $parameters An associative array of connection parameters,
|
||||
* or a valid connection URI as a string. If supplying an array, the following
|
||||
* paramters are accepted: host, port, user and pass. Any other parameters
|
||||
* are discarded.
|
||||
* @return mixed The connection parameters as an associative array, or false
|
||||
* if the parameters could not be parsed. The array will have the following
|
||||
* keys: host, port, user and pass.
|
||||
* @access private
|
||||
*/
|
||||
private function parseParameters($parameters) {
|
||||
|
||||
if (is_string($parameters)) {
|
||||
$parameters = preg_replace('#^[a-z]+://#i', '', trim($parameters));
|
||||
if (!$parameters = parse_url('http://' . $parameters)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_array($parameters)) {
|
||||
// if parameters are not a string or an array, something is wrong
|
||||
return false;
|
||||
}
|
||||
|
||||
$defaults = array(
|
||||
'host' => 'localhost',
|
||||
'port' => 8080,
|
||||
'user' => null,
|
||||
'pass' => null
|
||||
);
|
||||
$parameters = array_intersect_key(array_merge($defaults, $parameters), $defaults);
|
||||
return $parameters;
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue