You are here

abstract class clients_connection_base in Web Service Clients 7

Same name and namespace in other branches
  1. 6.2 clients.inc \clients_connection_base
  2. 7.3 includes/clients.entity.inc \clients_connection_base
  3. 7.2 clients.inc \clients_connection_base

Base class for Client connections.

Hierarchy

Expanded class hierarchy of clients_connection_base

File

./clients.inc, line 11
Base class for backends. Handles XML-RPC, REST calls and caching results

View source
abstract class clients_connection_base {

  // Class properties.
  public $name;
  public $cid;
  public $endpoint;
  public $configuration;

  /**
   * Submit handler for saving/updating connections of this class.
   *
   * @see clients_connection_form_submit().
   */
  static function connectionSettingsForm_submit($form, &$form_state) {

    // Base class does nothing; saving of the connection is handled by the
    // 'real' FormAPI submit handler.
  }

  /**
   * Constructor method.
   *
   * @param $connection_data
   *  An object containing connection data, as returned from clients_connection_load().
   */
  function __construct($connection_data) {

    // Set the connection properties.
    // TODO: incoming $connection_data should change to an array in due course.
    foreach (array(
      'name',
      'cid',
      'endpoint',
      'configuration',
      'type',
    ) as $property) {
      $this->{$property} = $connection_data->{$property};
    }
  }

  /**
   * Takes variable number of params after cacheid.
   */
  protected static function doCall($method, $cacheid) {
    $args = func_get_args();
    $args = array_slice($args, 2);

    // any extra params passed to this argument
    $cache_table = 'cache_clients';
    $cache_time = variable_get('clients_api_cache_time', '0');
    if ($cache_time == '0' || !($result = cache_get($cacheid, $cache_table))) {
      if ($method == 'xmlrpc') {
        $data = call_user_func_array('xmlrpc', $args);
      }
      elseif ($method == 'rest') {
        $data = call_user_func_array('drupal_http_request', $args);
      }
      else {
        $data = t('@method not yet supported', array(
          '@method' => $method,
        ));
      }

      // @todo error handling/reporting
      if ($cache_time != '0') {
        cache_set($cacheid, $data, $cache_table, $cache_time == 'cron' ? CACHE_TEMPORARY : time() + (int) $cache_time * 60);
      }
      $result = new stdClass();
      $result->data = $data;
      $result->created = time();
    }
    return $result;
  }

  /**
   * Provide buttons for the connection testing page.
   */
  function getTestOperations() {
    return array();
  }

  /**
   * Connection extending classes must implement the interface below:
   */

  /**
   * Sets cacheid and parameters for the service/method and calls self::doCall()
   */
  public static abstract function call($serviceConfig, $serviceOptions);

}

Members

Namesort descending Modifiers Type Description Overrides
clients_connection_base::$cid public property
clients_connection_base::$configuration public property
clients_connection_base::$endpoint public property
clients_connection_base::$name public property
clients_connection_base::call abstract public static function Sets cacheid and parameters for the service/method and calls self::doCall() 2
clients_connection_base::connectionSettingsForm_submit static function Submit handler for saving/updating connections of this class. 1
clients_connection_base::doCall protected static function Takes variable number of params after cacheid.
clients_connection_base::getTestOperations function Provide buttons for the connection testing page. 1
clients_connection_base::__construct function Constructor method. 1