You are here

function _acquia_purge_variable in Acquia Purge 7

Retrieve a Drupal variable or its default.

The sole reason this helper exists is to prevent a wilderness of direct calls to variable_get() and to mitigate the risk of different default values. In Drupal 8, this problem is addressed in its shiny configuration API but here we have to deal with it this way by keeping all defaults in one place.

Parameters

string $name: The name of the variable to return.

Return value

bool|string|array The value of the variable or its default.

See also

variable_get()

23 calls to _acquia_purge_variable()
AcquiaPurgeExecutorBase::__construct in lib/executor/AcquiaPurgeExecutorBase.php
Construct a new AcquiaPurgeExecutorBase instance.
AcquiaPurgeHostingInfo::areDomainsHardcoded in lib/AcquiaPurgeHostingInfo.php
Are the domains manually hardcoded?
AcquiaPurgeHostingInfo::domains in lib/AcquiaPurgeHostingInfo.php
Initialize $this->domains.
AcquiaPurgeHostingInfo::domainsAddFromSitesPhp in lib/AcquiaPurgeHostingInfo.php
Source domains from sites/sites.php by reverse parsing it.
AcquiaPurgeHostingInfo::__construct in lib/AcquiaPurgeHostingInfo.php
Constructs a AcquiaPurgeHostingInfo object.

... See full list

File

./acquia_purge.module, line 856
Acquia Purge, Top-notch Varnish purging on Acquia Cloud!

Code

function _acquia_purge_variable($name) {
  static $defaults;
  if (is_null($defaults)) {

    // All default variable values, see INSTALL.md as well for further info.
    $defaults = array(
      'acquia_purge_domains' => FALSE,
      'acquia_purge_sphpskippath' => TRUE,
      'acquia_purge_stripports' => array(
        80,
        443,
        8080,
      ),
      'acquia_purge_cron' => TRUE,
      'acquia_purge_lateruntime' => FALSE,
      'acquia_purge_http' => TRUE,
      'acquia_purge_https' => FALSE,
      'acquia_purge_token' => FALSE,
      // For the usage of $GLOBALS, see https://www.drupal.org/node/2506881.
      'acquia_purge_base_path' => $GLOBALS['base_path'],
      'acquia_purge_errorlimit' => TRUE,
      'acquia_purge_log_success' => TRUE,
      'acquia_purge_variations' => TRUE,
      'acquia_purge_memcache' => TRUE,
      'acquia_purge_trim_slashes' => TRUE,
      'acquia_purge_passivemode' => FALSE,
      'acquia_purge_silentmode' => FALSE,
      'acquia_purge_allriskmode' => FALSE,
      'acquia_purge_smartqueue' => FALSE,
    );

    // Add all code registry services so that these can be overloaded.
    foreach (_acquia_purge_registry()['services'] as $service => $dfltclass) {
      $defaults[$service] = $dfltclass;
    }
  }

  // Be explicit about requested variables we don't know about.
  if (!isset($defaults[$name])) {
    throw new Exception("_acquia_purge_variable: invalid variable '{$name}'!");
  }
  return variable_get($name, $defaults[$name]);
}