You are here

function clients_connection_load in Web Service Clients 7.3

Same name and namespace in other branches
  1. 6.2 clients.module \clients_connection_load()
  2. 6 clients.module \clients_connection_load()
  3. 7 clients.module \clients_connection_load()
  4. 7.2 clients.module \clients_connection_load()

Load a connection object which can then be used to make method calls.

If the 'environment_name' variable is set, this will try to load a connection with the environment name appended to the connection name. This allows the the use of connections to development services on a development site.

Because of the extra overhead in first trying to load the connection with the suffix, it is advisable to not set the 'environment_name' variable on a production site.

Parameters

$connection_name: A connection machine name.

Return value

A fully loaded connection handler object. If there is a problem, such as the machine name or connection type not existing, a connection of the class defined for broken handlers in hook_entity_info() is returned.

3 calls to clients_connection_load()
ClientsTestCase::testConnectionCall in tests/clients.test
Test a basic call to the dummy connection.
clients_connection_call in ./clients.module
Call a remote method on a client.
clients_resource_base::getConnection in includes/clients.entity.inc
Get this resource's connection
1 string reference to 'clients_connection_load'
clients_connection_form in includes/clients.connection.admin.inc
Form builder for editing a connection.

File

./clients.module, line 185
Clients module provides a UI, storage, and an API for handling connections to remote webservices, including those provided by Services module on other Drupal sites.

Code

function clients_connection_load($connection_name) {

  // If the the local environment is set and not 'production', we look for an
  // environment-specific connection.
  $environment_name = variable_get('environment_name', NULL);
  if (isset($environment_name) && $environment_name != 'production') {

    // Append the environment name to the connection name, and try to load
    // that connection instead.
    $connection_name_environment = $connection_name . '_' . $environment_name;
    if ($connection = entity_load_single('clients_connection', $connection_name_environment)) {
      return $connection;
    }
  }
  return entity_load_single('clients_connection', $connection_name);
}