You are here

function _acquia_purge_registry in Acquia Purge 7

Retrieve the Acquia Purge code registry.

Although Drupal 7 has its own code registry, we can't rely on it without taking the risk of breaking upgrading sites. Since we introduced an object oriented core in 7.x-1.3, all the legacy code got decoupled into many different classes.

The registry is simple and has low overhead. It parses acquia_purge.info once the parsed information is stored using cache_set(). Everytime changes are made to acquia_purge.info, the '_v<N>' cache key is manually changed to let upgrading users automatically rebuild it.

Return value

array[] Acquia Purge code registry array, with the following keys:

  • 'classes': assoc. array with class names as key, path-array as value.
  • 'services': assoc. array with service names as key, classes as value.
  • 'paths': array with path names, key's are referred to from 'classes'.

See also

acquia_purge.info

_acquia_purge_load

1 call to _acquia_purge_registry()
_acquia_purge_load in ./acquia_purge.module
Load code on which Acquia Purge depends.

File

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

Code

function _acquia_purge_registry() {
  static $registry;
  if (is_null($registry)) {
    $cache_key = ACQUIA_PURGE_CID_PREFIX . '_registry';
    if ($cache = cache_get($cache_key)) {
      $registry = $cache->data;
    }
    else {

      // Parse the module's .info file to retrieve all registered files.
      require_once DRUPAL_ROOT . '/includes/common.inc';
      $path = drupal_get_path('module', 'acquia_purge') . '/acquia_purge.info';
      $info = drupal_parse_info_file($path);

      // Begin the registry's datastructure.
      $registry = array(
        'classes' => array(),
        'services' => array(),
        'paths' => array(),
      );

      // Add each files[] row in the .info file, to the $registry variable.
      foreach ($info['files'] as $path) {

        // Add the class with the number of paths so far as orderable ID.
        $class = str_replace('.php', '', basename($path));
        $registry['classes'][$class] = count($registry['paths']);

        // Add the path to the second listing.
        $registry['paths'][] = $path;

        // Generate a service name based on the class by applying a few rules.
        $service = str_replace('AcquiaPurge', '', $class);
        $service = preg_replace('/(?<!^)[A-Z]/', '_$0', $service);
        $service = str_replace('_service', '', drupal_strtolower($service));
        $registry['services']['_acquia_purge_' . $service] = $class;
      }
      cache_set($cache_key, $registry);
    }
  }
  return $registry;
}