You are here

public static function Composer::getVersionHash in Markdown 8.2

Retrieves the pre-generated version hash.

@internal

Parameters

string $name: Optional. A specific package of hashes to retrieve.

int $sort: The sort direction to use when returning the hashes. By default, this uses a descending order to ensure that if there are multiple versions with the same hash, the latest version will be returned. While this is a wild assumption, it's also the best that can be done provided that there wasn't enough significant changes made to the codebase to generate a unique hash; thus, they're effectively running the latest version of that hash.

Return value

array If $name was provided, an associative array of hashes are returned where the key is the version. If not provided, then the entire version hash array is returned where the keys are the package names and the values are an associative array as defined above.

Deprecated

in markdown:8.x-2.0 and is removed from markdown:4.0.0. No replacement.

See also

https://www.drupal.org/project/markdown/issues/3200476

1 call to Composer::getVersionHash()
Composer::getVersionFromClass in src/Util/Composer.php
Retrieves the version based on a provided class name.

File

src/Util/Composer.php, line 266

Class

Composer
Helper class used to deal with composer.

Namespace

Drupal\markdown\Util

Code

public static function getVersionHash($name = NULL, $sort = Semver::SORT_DESC) {
  if (!static::$versionHash) {
    $cache = \Drupal::cache('markdown');
    $cid = 'composer.version:hash';
    if (($cached = $cache
      ->get($cid)) && isset($cached->data)) {
      static::$versionHash = $cached->data;
    }
    else {
      $file = __DIR__ . '/../../' . Composer::VERSION_HASH_FILE_NAME;
      static::$versionHash = file_exists($file) ? Json::decode(file_get_contents($file)) : [];
      $cache
        ->set($cid, static::$versionHash);
    }
  }
  if ($name) {
    $hashes = isset(static::$versionHash[$name]) ? static::$versionHash[$name] : [];
    Semver::ksort($hashes, $sort);
    return $hashes;
  }
  return static::$versionHash;
}