From 7b49b013ec85c8a0d5cfe8b71ec2f720bc6048a4 Mon Sep 17 00:00:00 2001 From: Christian Riesen Date: Fri, 22 Jun 2012 13:51:26 +0200 Subject: [PATCH 1/4] PlatformRepository now knows curl and libxml versions --- .../Repository/PlatformRepository.php | 57 +++++++++++++++---- 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/src/Composer/Repository/PlatformRepository.php b/src/Composer/Repository/PlatformRepository.php index 495155276..32380eff2 100644 --- a/src/Composer/Repository/PlatformRepository.php +++ b/src/Composer/Repository/PlatformRepository.php @@ -40,17 +40,52 @@ class PlatformRepository extends ArrayRepository parent::addPackage($php); foreach (get_loaded_extensions() as $name) { - if (in_array($name, array('standard', 'Core'))) { - continue; - } - - $reflExt = new \ReflectionExtension($name); - try { - $prettyVersion = $reflExt->getVersion(); - $version = $versionParser->normalize($prettyVersion); - } catch (\UnexpectedValueException $e) { - $prettyVersion = '0'; - $version = $versionParser->normalize($prettyVersion); + 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); + } + + break; } $ext = new MemoryPackage('ext-'.$name, $version, $prettyVersion); From 8d3c85225ff4a0c622563b5a3497c3ad40afe5c9 Mon Sep 17 00:00:00 2001 From: Christian Riesen Date: Fri, 22 Jun 2012 14:54:03 +0200 Subject: [PATCH 2/4] 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); + } } } From 432815df673d85e6df8553ef2d621459a4fef5b5 Mon Sep 17 00:00:00 2001 From: Christian Riesen Date: Fri, 22 Jun 2012 15:46:36 +0200 Subject: [PATCH 3/4] Added more libraries to PlatformRepository --- .../Repository/PlatformRepository.php | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/Composer/Repository/PlatformRepository.php b/src/Composer/Repository/PlatformRepository.php index a61fb2a64..5947a8442 100644 --- a/src/Composer/Repository/PlatformRepository.php +++ b/src/Composer/Repository/PlatformRepository.php @@ -69,32 +69,50 @@ class PlatformRepository extends ArrayRepository } // Another quick loop, just for possible libraries + // Doing it this way to know that functions or constants exist before + // relying on them. 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 'iconv': + $prettyVersion = ICONV_VERSION; + break; + case 'libxml': $prettyVersion = LIBXML_DOTTED_VERSION; break; - + case 'openssl': $prettyVersion = str_replace('OpenSSL', '', OPENSSL_VERSION_TEXT); $prettyVersion = trim($prettyVersion); break; - + + case 'mysqli': + // not so pretty version + $prettyVersion = mysqli_get_client_version(); + break; + case 'pcre': $prettyVersion = PCRE_VERSION; break; + case 'uuid': + $prettyVersion = UUID_VERSION; + break; + + case 'xsl': + $prettyVersion = LIBXSLT_DOTTED_VERSION; + break; + default: // None handled extensions have no special cases, skip continue; From 70e7194b07a47e62caa8a5a79df8fb9c53d5d35b Mon Sep 17 00:00:00 2001 From: Christian Riesen Date: Fri, 22 Jun 2012 17:16:07 +0200 Subject: [PATCH 4/4] Changes after excellent feedback from Jordi --- .../Repository/PlatformRepository.php | 30 ++++--------------- 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/src/Composer/Repository/PlatformRepository.php b/src/Composer/Repository/PlatformRepository.php index 5947a8442..4939b6b96 100644 --- a/src/Composer/Repository/PlatformRepository.php +++ b/src/Composer/Repository/PlatformRepository.php @@ -43,20 +43,13 @@ class PlatformRepository extends ArrayRepository // Extensions scanning foreach ($loadedExtensions as $name) { - switch ($name) { - // Skipped "extensions" - case 'standard': - case 'Core': - continue; - - // All normal cases for standard extensions - default: - $reflExt = new \ReflectionExtension($name); - $prettyVersion = $reflExt->getVersion(); - break; + if (in_array($name, array('standard', 'Core'))) { + continue; } - + + $reflExt = new \ReflectionExtension($name); try { + $prettyVersion = $reflExt->getVersion(); $version = $versionParser->normalize($prettyVersion); } catch (\UnexpectedValueException $e) { $prettyVersion = '0'; @@ -73,11 +66,6 @@ class PlatformRepository extends ArrayRepository // relying on them. foreach ($loadedExtensions as $name) { switch ($name) { - // Skipped "extensions" - case 'standard': - case 'Core': - continue; - case 'curl': $curlVersion = curl_version(); $prettyVersion = $curlVersion['version']; @@ -96,11 +84,6 @@ class PlatformRepository extends ArrayRepository $prettyVersion = trim($prettyVersion); break; - case 'mysqli': - // not so pretty version - $prettyVersion = mysqli_get_client_version(); - break; - case 'pcre': $prettyVersion = PCRE_VERSION; break; @@ -121,8 +104,7 @@ class PlatformRepository extends ArrayRepository try { $version = $versionParser->normalize($prettyVersion); } catch (\UnexpectedValueException $e) { - $prettyVersion = '0'; - $version = $versionParser->normalize($prettyVersion); + continue; } $ext = new MemoryPackage('lib-'.$name, $version, $prettyVersion);