function salvattore_get_version in Salvattore (CSS driven Masonry) 8
Same name and namespace in other branches
- 7.2 salvattore.module \salvattore_get_version()
Guesses the salvattore library version.
This function is using a regex, which assumes that the format of the version string won't change. If it changes, feel free to submit a bug report.
Return value
mixed The version number if exists, or a boolean FALSE if it can't be determined.
1 call to salvattore_get_version()
- salvattore_requirements in ./salvattore.install 
- Implements hook_requirements().
File
- ./salvattore.module, line 120 
- Salvattore masonry plugin for views.
Code
function salvattore_get_version($reset = FALSE) {
  $version =& drupal_static(__FUNCTION__);
  if ($version === NULL || $reset == TRUE) {
    if ($cached = \Drupal::cache()
      ->get('salvattore_version') && isset($cached->data) && $reset != TRUE) {
      $version = $cached->data;
    }
    else {
      $version = FALSE;
      $salvattore_path = salvattore_get_path();
      if (file_exists($salvattore_path)) {
        $salvattore = file_get_contents($salvattore_path);
        $matches = array();
        preg_match(SALVATTORE_VERSION_REGEX, $salvattore, $matches);
        if (isset($matches[0])) {
          $version = $matches[0];
          if ($version) {
            \Drupal::cache()
              ->set('salvattore_version', $version);
          }
        }
        unset($salvattore);
      }
    }
  }
  return $version;
}