You are here

function cf_version_exists in Common Functionality 7.2

Detect if a specific version of a module exists.

If the module does not define a version setting in the *.info file, then this function will fail to detect the version number.

Justification: Modules may need to act differently based on the version number of a particular module.

References:

Parameters

string $module: The name of the module (without the .module extension).

string $version: The desired version number.

bool $exact: (optional) When FALSE, a regular expression is performed against the passed version number. When TRUE, only the exact version number will be accepted.

Return value

bool Returns TRUE when the version of a module matches the requested version, FALSE otherwise.

Related topics

File

./cf.module, line 435
Common Functionality module.

Code

function cf_version_exists($module, $version, $exact = FALSE) {
  if (cf_is_empty_or_non_string('module', $module)) {
    return FALSE;
  }
  if (cf_is_empty_or_non_string('version', $version)) {
    return FALSE;
  }
  if (!is_bool($exact)) {
    if (class_exists('cf_error')) {
      cf_error::invalid_bool('exact');
    }
    return FALSE;
  }
  if (!module_exists($module)) {
    return FALSE;
  }
  $path = drupal_get_path('module', $module);
  $info = drupal_parse_info_file($path . '/' . $module . '.info');
  if ($exact) {
    return $info['version'] == $version;
  }
  return preg_match('/^(' . $version . '|' . $version . '\\..*)$/i', $info['version']);
}