You are here

function js_server_info in JS Callback Handler 7.2

Provides server information provided by modules.

Parameters

string $server: The name of a server to retrieve.

bool $reset: For internal use only: Whether to force the stored list of hook implementations to be regenerated (such as after enabling a new module, before processing hook_enable).

Return value

array|false If $server is provided the info array for the specified server is returned or FALSE if it's not defined. If no parameters are provided, all modules that provided server information is returned.

1 call to js_server_info()
js_configure_form in ./js.admin.inc
Form callback for the JS configuration form.

File

./js.module, line 221
JavaScript callback handler module.

Code

function js_server_info($server = NULL, $reset = FALSE) {

  // Use the advanced drupal_static() pattern, since this has the potential to
  // be called quite often on a single page request.
  static $drupal_static_fast;
  if (!isset($drupal_static_fast)) {
    $drupal_static_fast['servers'] =& drupal_static(__FUNCTION__);
  }
  $servers =& $drupal_static_fast['servers'];

  // Populate servers. Using cache if possible or rebuild if necessary.
  if ($reset || !isset($servers)) {
    $servers = array();
    $cid = 'js:servers';
    if (!$reset && ($cache = cache_get($cid)) && $cache->data) {
      $servers = $cache->data;
    }
    else {
      foreach (module_implements('js_server_info', FALSE, $reset) as $module) {
        $results = module_invoke($module, 'js_server_info');

        // Iterate over each module and retrieve the server info.
        foreach ($results as $name => $info) {
          $servers[$name] = (array) $info;

          // Provide defaults if the module didn't provide them.
          $servers[$name] += array(
            'description' => '',
            'label' => $name,
            'regexp' => "/{$name}/i",
            'rewrite' => '',
          );

          // Ensure "name" and "module" are always provided by discovery.
          $servers[$name]['name'] = $name;
          $servers[$name]['module'] = $module;

          // Convert "rewrite" to strings if it's an array.
          if (is_array($servers[$name]['rewrite'])) {
            $servers[$name]['rewrite'] = implode("\n", $servers[$name]['rewrite']);
          }
        }
      }

      // Invokes hook_js_server_info_alter(). Allow modules to alter the
      // server info before it's cached in the database.
      drupal_alter('js_server_info', $servers);
      cache_set($cid, $servers);
    }
  }

  // Return a specific callback for a module.
  if (isset($server)) {
    return !empty($servers[$server]) ? $servers[$server] : FALSE;
  }

  // Return all server info implemented by any module.
  return $servers;
}