You are here

function _acquia_purge_load in Acquia Purge 7

Load code on which Acquia Purge depends.

This function is a complex code loader and dependency injection container for Acquia Purge's object oriented core, which got introduced in 7.x-1.3. From files listed in acquia_purge.info, a "service name" is derived that is used as primary $dependency value throughout the Acquia Purge code.

This "dependency name" is generated by _acquia_purge_registry() and gets then fed to _acquia_purge_variable(). The latter comes up with the default class name or a file path when the dependency name is overridden using the variable system. This allows all classes to be swapped from settings.php like this:

  • $conf['_acquia_purge_service'] = "sites/all/modules/custommodule/s.php";
  • $conf['_acquia_purge_hosting_info'] = "sites.../myhostinginfo.php";

In order to find all default services and the classes they point to, run: $ drush php-eval "print_r(_acquia_purge_registry()['services']);"

The name of the derived file is assumed to also be the name of the class it contains, so if the "_acquia_purge_executors" service is pointed to the path "sites/all/modules/my/MyExecutor.php", the returned $class value is going to be "MyExecutor". Acquia Purge will instantiate that class by its derived name, so make sure to not just copy a file but rename the class!

Parameters

string|string[] $dependency:

  • string[]: Unassociative array of dependencies, the last sets the class.
  • string: a relative or absolute file path (must contain '.' character).
  • string: dependency name derived from acquia_purge.info, see the drush command hereabove to find the possible values.

Return value

string The name of the class defined in the requested dependency.

See also

_acquia_purge_registry

17 calls to _acquia_purge_load()
AcquiaPurgeExecutorBase::__construct in lib/executor/AcquiaPurgeExecutorBase.php
Construct a new AcquiaPurgeExecutorBase instance.
AcquiaPurgeExecutorsService::__construct in lib/executor/AcquiaPurgeExecutorsService.php
Construct a new AcquiaPurgeExecutorsService instance.
AcquiaPurgeProcessorsService::__construct in lib/processor/AcquiaPurgeProcessorsService.php
Construct a new AcquiaPurgeProcessorsService instance.
AcquiaPurgeQueueEfficient::__construct in lib/queue/AcquiaPurgeQueueEfficient.php
Construct a AcquiaPurgeQueueEfficient instance.
AcquiaPurgeQueueItem::__construct in lib/queue/AcquiaPurgeQueueItem.php
Constructs an queue item object.

... See full list

File

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

Code

function _acquia_purge_load($dependency) {

  // When $dependency is an array, load all items and return the last class.
  if (is_array($dependency)) {
    foreach ($dependency as $subdependency) {
      $class = _acquia_purge_load($subdependency);
    }
    return $class;
  }

  // Initialize statically cached variables.
  static $path_module, $loaded;
  if (is_null($path_module)) {
    require_once DRUPAL_ROOT . '/includes/common.inc';
    require_once DRUPAL_ROOT . '/' . variable_get('path_inc', 'includes/path.inc');
    require_once DRUPAL_ROOT . '/includes/cache.inc';
    require_once DRUPAL_ROOT . '/includes/unicode.inc';
    $path_module = DRUPAL_ROOT . '/' . drupal_get_path('module', 'acquia_purge');
  }
  if (is_null($loaded)) {
    $loaded = array();
  }

  // Retrieve the code registry.
  $registry = _acquia_purge_registry();

  // SERVICES: lookup the actual class and file and recurse.
  $dependency_is_a_service = !(strpos($dependency, '.') !== FALSE);
  if ($dependency_is_a_service) {
    $class_or_path = _acquia_purge_variable($dependency);
    if (!(strpos($class_or_path, '.') !== FALSE)) {
      $path_index = $registry['classes'][$class_or_path];
      $class_or_path = $registry['paths'][$path_index];
    }
    if (!(strpos($class_or_path, '.') !== FALSE)) {
      throw new LogicException("{$variable} doesn't point to a class known to AP or a file on disk.");
    }
    return _acquia_purge_load($class_or_path);
  }
  elseif (strpos($dependency, 'lib/') === 0) {
    $dependency = $path_module . '/' . $dependency;

    // The files in acquia_purge.info are ordered by dependency order, so we
    // always load files defined prior to our dependency.
    $load_up_to_index = FALSE;
    foreach ($registry['paths'] as $index => $path) {
      $path = $path_module . '/' . $path;
      if (strpos($dependency, $path) === 0) {
        $load_up_to_index = $index;
      }
    }
    if ($load_up_to_index) {
      foreach ($registry['paths'] as $index => $path) {
        $path = $path_module . '/' . $path;
        if (in_array($path, $loaded)) {
          continue;
        }
        if ($index < $load_up_to_index) {
          _acquia_purge_load($path);
        }
      }
    }
    return _acquia_purge_load($dependency);
  }
  else {
    if (!in_array($dependency, $loaded)) {
      $loaded[] = $dependency;
      require_once $dependency;
    }

    // Return the classname which to help instantiating it.
    return str_replace('.php', '', basename($dependency));
  }
}