You are here

abstract class clients_connection_base in Web Service Clients 6.2

Same name and namespace in other branches
  1. 7.3 includes/clients.entity.inc \clients_connection_base
  2. 7 clients.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 10
Contains basic classes for client connections.

View source
abstract class clients_connection_base {

  /**
   * The machine name of the connection.
   */
  public $name;

  /**
   * The connection id. Only set if this is stored in the database.
   */
  public $cid;

  /**
   * The URL this connection connects to.
   */
  public $endpoint;

  /**
   * An array of further configuration options.
   */
  public $configuration;

  // ============================================ Connection UI

  /**
   * Format the connection's endpoint as a link.
   *
   * @param $url
   *  The connection's endpoint.
   *
   * @return
   *  The string to display in the admin UI. Subclasses may format this as a
   *  link to the remote site.
   */
  function formatEndpoint($url) {
    return $url;
  }

  /**
   * Extra form elements specific to a class's edit form.
   *
   * This is the same pattern as node_form() -- just ignore the object behind
   * the curtain ;)
   *
   * This (so far) is common to all versions of Drupal Services.
   *
   * @param $form_state
   *  The form state from the main form, which you probably don't need anyway.
   *
   * @return
   *  A FormAPI form array. This will be merged in with basic data and the
   *  submit button added.
   *
   * @see clients_connection_form()
   * @see clients_connection_form()
   * @see clients_connection_form_submit()
   */
  function connectionSettingsForm(&$form_state) {
    $form = array();
    return $form;
  }

  /**
   * 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.
  }

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

  // ============================================ Constructor.

  /**
   * Constructor method.
   *
   * @param $object
   *  An object of class stdClass returned from CTools.
   */
  function __construct($object) {

    // Lump all data unto the object...
    foreach ((array) $object as $field => $value) {
      $this->{$field} = $value;
    }

    // Connections defined in code are already unserialized.
    if (!is_array($object->configuration)) {
      $this->configuration = unserialize($object->configuration);
    }
    return $this;
  }

  // ============================================ Connection API.

  /**
   * Call a remote method.
   *
   * This is a wrapper around callMethodArray that gives the convenience of
   * being able to pass method name and parameters as one flat list, and hence
   * is the main API for connection objects.
   *
   * @param $method
   *  The name of the remote method to call.
   * @param ...
   *  All other parameters are passed to the remote method.
   *
   * @return
   *  Whatever is returned from the remote site.
   *
   * @throws Exception on error from the remote site.
   */
  function callMethod($method) {

    // Get all the arguments this function has been passed.
    $function_args = func_get_args();

    // Slice out the ones that are arguments to the method call: everything past
    // the 1st argument.
    $method_params = array_slice($function_args, 1);
    return $this
      ->callMethodArray($method, $method_params);
  }

  /**
   * Call a remote method with an array of parameters.
   *
   * This is intended for internal use from callMethod() and
   * clients_connection_call().
   * If you need to call a method on given connection object, use callMethod
   * which has a nicer form.
   *
   * @param $method
   *  The name of the remote method to call.
   * @param $method_params
   *  An array of parameters to passed to the remote method.
   *
   * @return
   *  Whatever is returned from the remote site.
   *
   * @throws Exception on error from the remote site.
   *  It's up to subclasses to implement this, as the test for an error and
   *  the way to get information about it varies according to service type.
   */
  function callMethodArray($method, $method_params = array()) {

    // Up to subclasses to override this to do something.
  }

}

Members

Namesort descending Modifiers Type Description Overrides
clients_connection_base::$cid public property The connection id. Only set if this is stored in the database.
clients_connection_base::$configuration public property An array of further configuration options.
clients_connection_base::$endpoint public property The URL this connection connects to.
clients_connection_base::$name public property The machine name of the connection.
clients_connection_base::callMethod function Call a remote method.
clients_connection_base::callMethodArray function Call a remote method with an array of parameters. 3
clients_connection_base::connectionSettingsForm function Extra form elements specific to a class's edit form. 2
clients_connection_base::connectionSettingsForm_submit static function Submit handler for saving/updating connections of this class. 2
clients_connection_base::formatEndpoint function Format the connection's endpoint as a link. 2
clients_connection_base::getTestOperations function Provide buttons for the connection testing page. 1
clients_connection_base::__construct function Constructor method. 2