You are here

public function AcsfSite::__construct in Acquia Cloud Site Factory Connector 8

Same name and namespace in other branches
  1. 8.2 src/AcsfSite.php \Drupal\acsf\AcsfSite::__construct()

Constructor.

Parameters

int $site_id: The site id from the Site Factory (Optional).

Throws

AcsfSiteMissingIdentifierException

File

src/AcsfSite.php, line 54

Class

AcsfSite
AcsfSite.

Namespace

Drupal\acsf

Code

public function __construct($site_id = NULL) {

  // @todo properly inject this?
  $this->variableStorage = \Drupal::service('acsf.variable_storage');
  if (empty($site_id) && !empty($GLOBALS['gardens_site_settings']['conf']['acsf_site_id'])) {

    // If we do not have the site id, we can retrieve it from the sites.json.
    $site_id = $GLOBALS['gardens_site_settings']['conf']['acsf_site_id'];
  }

  // If we are on Acquia hosting, ensure that we are connected to a Factory.
  if (function_exists('is_acquia_host') && is_acquia_host() && empty($site_id)) {
    throw new AcsfSiteMissingIdentifierException('Cannot instantiate AcsfSite without a site id from the Site Factory. Ensure that it is passed to the constructor or set in sites.json.');
  }

  // Init with the stored values.
  $this
    ->initStoredSiteInfo();

  // Merge in any global values from the sites.json.
  if (!empty($GLOBALS['gardens_site_settings']['conf'])) {
    $this
      ->mergeSiteInfo($GLOBALS['gardens_site_settings']['conf']);
  }

  // Some of the data is redundant.
  unset($this->gardens_site_id);
  unset($this->gardens_db_name);
  unset($this->acsf_site_id);
  unset($this->acsf_db_name);
  $this->site_id = $site_id;
}