From 8d3c85225ff4a0c622563b5a3497c3ad40afe5c9 Mon Sep 17 00:00:00 2001 From: Christian Riesen Date: Fri, 22 Jun 2012 14:54:03 +0200 Subject: [PATCH] Changed PlatformRepository to handle libraries as well now --- .../Repository/PlatformRepository.php | 95 +++++++++++-------- 1 file changed, 57 insertions(+), 38 deletions(-) diff --git a/src/Composer/Repository/PlatformRepository.php b/src/Composer/Repository/PlatformRepository.php index 32380eff2..a61fb2a64 100644 --- a/src/Composer/Repository/PlatformRepository.php +++ b/src/Composer/Repository/PlatformRepository.php @@ -38,59 +38,78 @@ class PlatformRepository extends ArrayRepository $php = new MemoryPackage('php', $version, $prettyVersion); $php->setDescription('The PHP interpreter'); parent::addPackage($php); - - foreach (get_loaded_extensions() as $name) { + + $loadedExtensions = get_loaded_extensions(); + + // Extensions scanning + foreach ($loadedExtensions as $name) { switch ($name) { // Skipped "extensions" case 'standard': case 'Core': continue; - - // Curl exposes its version by the curl_version function - case 'curl': - $curlversion = curl_version(); - $prettyVersion = $curlversion['version']; - - try { - $version = $versionParser->normalize($prettyVersion); - } catch (\UnexpectedValueException $e) { - $prettyVersion = '0'; - $version = $versionParser->normalize($prettyVersion); - } - - break; - - - case 'libxml': - $prettyVersion = LIBXML_DOTTED_VERSION; - - try { - $version = $versionParser->normalize($prettyVersion); - } catch (\UnexpectedValueException $e) { - $prettyVersion = '0'; - $version = $versionParser->normalize($prettyVersion); - } - - break; // All normal cases for standard extensions default: $reflExt = new \ReflectionExtension($name); - - try { - $prettyVersion = $reflExt->getVersion(); - $version = $versionParser->normalize($prettyVersion); - } catch (\UnexpectedValueException $e) { - $prettyVersion = '0'; - $version = $versionParser->normalize($prettyVersion); - } - + $prettyVersion = $reflExt->getVersion(); break; } + + try { + $version = $versionParser->normalize($prettyVersion); + } catch (\UnexpectedValueException $e) { + $prettyVersion = '0'; + $version = $versionParser->normalize($prettyVersion); + } $ext = new MemoryPackage('ext-'.$name, $version, $prettyVersion); $ext->setDescription('The '.$name.' PHP extension'); parent::addPackage($ext); } + + // Another quick loop, just for possible libraries + foreach ($loadedExtensions as $name) { + switch ($name) { + // Skipped "extensions" + case 'standard': + case 'Core': + continue; + + // Curl exposes its version by the curl_version function + case 'curl': + $curlVersion = curl_version(); + $prettyVersion = $curlVersion['version']; + break; + + case 'libxml': + $prettyVersion = LIBXML_DOTTED_VERSION; + break; + + case 'openssl': + $prettyVersion = str_replace('OpenSSL', '', OPENSSL_VERSION_TEXT); + $prettyVersion = trim($prettyVersion); + break; + + case 'pcre': + $prettyVersion = PCRE_VERSION; + break; + + default: + // None handled extensions have no special cases, skip + continue; + } + + try { + $version = $versionParser->normalize($prettyVersion); + } catch (\UnexpectedValueException $e) { + $prettyVersion = '0'; + $version = $versionParser->normalize($prettyVersion); + } + + $ext = new MemoryPackage('lib-'.$name, $version, $prettyVersion); + $ext->setDescription('The '.$name.' PHP library'); + parent::addPackage($ext); + } } }