Ampache PHP Cross Reference Groupware Applications

Source: /modules/xbmc-php-rpc/Server.php - 88 lines - 2746 bytes - Summary - Text - Print

   1  <?php
   2  
   3  require_once  'ServerException.php';
   4  
   5  class XBMC_RPC_Server {
   6      
   7      /**
   8       * @var mixed An array of parameters used to connect to the server.
   9       * @access private
  10       */
  11      private $parameters = array();
  12      
  13      /**
  14       * Constructor.
  15       *
  16       * @param mixed $parameters An associative array of connection parameters,
  17       * or a valid connection URI as a string. If supplying an array, the following
  18       * paramters are accepted: host, port, user and pass. Any other parameters
  19       * are discarded.
  20       * @exception XBMC_RPC_ServerException if the supplied parameters could not
  21       * be parsed successfully.
  22       * @access public
  23       */
  24      public function __construct($parameters) {
  25          if (!$parameters = $this->parseParameters($parameters)) {
  26              throw new XBMC_RPC_ServerException('Unable to parse server parameters');
  27          }
  28          $this->parameters = $parameters;
  29      }
  30      
  31      /**
  32       * Checks if the server is connected.
  33       *
  34       * @return bool True if the server is connected, false if not.
  35       * @access public
  36       */
  37      public function isConnected() {
  38          return $this->connected;
  39      }
  40      
  41      /**
  42       * Gets the connection parameters/
  43       *
  44       * @return mixed The connection parameters as an associative array.
  45       * @access public
  46       */
  47      public function getParameters() {
  48          return $this->parameters;
  49      }
  50      
  51      /**
  52       * Parses the supplied parameters into a standard associative array format.
  53       *
  54       * @param mixed $parameters An associative array of connection parameters,
  55       * or a valid connection URI as a string. If supplying an array, the following
  56       * paramters are accepted: host, port, user and pass. Any other parameters
  57       * are discarded.
  58       * @return mixed The connection parameters as an associative array, or false
  59       * if the parameters could not be parsed. The array will have the following
  60       * keys: host, port, user and pass.
  61       * @access private
  62       */
  63      private function parseParameters($parameters) {
  64          
  65          if (is_string($parameters)) {
  66              $parameters = preg_replace('#^[a-z]+://#i', '', trim($parameters));
  67              if (!$parameters = parse_url('http://' . $parameters)) {
  68                  return false;
  69              }
  70          }
  71          
  72          if (!is_array($parameters)) {
  73              // if parameters are not a string or an array, something is wrong
  74              return false;
  75          }
  76          
  77          $defaults = array(
  78              'host' => 'localhost',
  79              'port' => 8080,
  80              'user' => null,
  81              'pass' => null
  82          );
  83          $parameters = array_intersect_key(array_merge($defaults, $parameters), $defaults);
  84          return $parameters;
  85  
  86      }
  87      
  88  }

title

Description

title

Description

title

Description

title

title

Body