You are here

public static function AcquiaLiftAPI::getInstance in Acquia Lift Connector 7

Same name and namespace in other branches
  1. 7.2 includes/AcquiaLiftAPI.inc \AcquiaLiftAPI::getInstance()

Singleton factory method.

Return value

AcquiaLiftAPI

13 calls to AcquiaLiftAPI::getInstance()
AcquiaLiftAgent::create in plugins/agent_types/AcquiaLiftAgent.inc
Implements PersonalizeAgentInterface::create().
AcquiaLiftContext::create in plugins/visitor_context/AcquiaLiftContext.inc
Implements PersonalizeContextInterface::create().
AcquiaLiftTest::getAcquiaLiftAPI in tests/AcquiaLiftAPI.test
Returns a AcquiaLiftAPI instance that can be used to test methods.
AcquiaLiftTest::testEnsureUniqueAgentName in tests/AcquiaLiftAPI.test
AcquiaLiftTest::testGetAgents in tests/AcquiaLiftAPI.test

... See full list

File

includes/acquia_lift.classes.inc, line 80
Provides an agent type for Acquia Lift

Class

AcquiaLiftAPI
@file Provides an agent type for Acquia Lift

Code

public static function getInstance($account_info) {
  if (empty(self::$instance)) {
    if (drupal_valid_test_ua()) {
      self::setTestInstance();
      return self::$instance;
    }
    foreach (array(
      'api_key',
      'admin_key',
      'owner_code',
    ) as $key) {
      if (!isset($account_info[$key])) {
        throw new AcquiaLiftCredsException('Acquia Lift account info is not complete.');
      }
    }
    if (!self::codeIsValid($account_info['owner_code'])) {
      throw new AcquiaLiftCredsException('Acquia Lift owner code is invalid.');
    }
    $api_url = self::API_URL;
    $needs_scheme = TRUE;
    if (!empty($account_info['api_url'])) {
      if (!valid_url($account_info['api_url'])) {
        throw new AcquiaLiftCredsException('Acquia Lift API URL is not a valid URL.');
      }
      $api_url = $account_info['api_url'];
      $needs_scheme = strpos($api_url, '://') === FALSE;
    }
    if ($needs_scheme) {
      global $is_https;

      // Use the same scheme for Acquia Lift as we are using here.
      $url_scheme = $is_https ? 'https://' : 'http://';
      $api_url = $url_scheme . $api_url;
    }
    if (substr($api_url, -1) === '/') {
      $api_url = substr($api_url, 0, -1);
    }
    self::$instance = new self($account_info['api_key'], $account_info['admin_key'], $account_info['owner_code'], $api_url);
  }
  return self::$instance;
}