You are here

protected function PeclExtension::detectVersion in Markdown 8.2

Detects the version of the library installed.

Return value

string|string[]|void The detected version, if any. If an array is returned, the first item should be the raw version provided by the library, the second item may contain additional meta information appended to the raw version to denote a more detailed version (i.e. bundled with another library).

Overrides InstallableLibrary::detectVersion

File

src/Annotation/PeclExtension.php, line 46

Class

PeclExtension
PeclExtension Annotation.

Namespace

Drupal\markdown\Annotation

Code

protected function detectVersion() {
  if (($name = $this
    ->getName()) && extension_loaded($name) && ($version = phpversion($name))) {

    // Extract any compiled "library" version associated with the extension.
    // @todo Revisit this to see if there's a better way.
    ob_start();
    phpinfo(INFO_MODULES);
    $contents = ob_get_contents();
    ob_clean();
    preg_match('/(lib-?' . preg_quote($name, '/') . ').*?v?\\s?(\\d+\\.\\d+(?:\\.\\d+)?)/', $contents, $matches);
    if (!empty($matches[2]) && (!$version || $version !== $matches[2])) {
      $libName = rtrim($matches[1], '-');
      $libVersion = $matches[2];
      $versionExtra = "{$version}+{$libName}-{$libVersion}";
    }
    return isset($versionExtra) ? [
      $version,
      $versionExtra,
    ] : $version;
  }
}