diff --git a/src/Composer/Platform/HhvmDetector.php b/src/Composer/Platform/HhvmDetector.php index a0524e758..ac63d047b 100644 --- a/src/Composer/Platform/HhvmDetector.php +++ b/src/Composer/Platform/HhvmDetector.php @@ -21,8 +21,8 @@ class HhvmDetector private $executableFinder; private $processExecutor; - public function __construct(ExecutableFinder $executableFinder = null, ProcessExecutor $processExecutor = null) { - + public function __construct(ExecutableFinder $executableFinder = null, ProcessExecutor $processExecutor = null) + { $this->executableFinder = $executableFinder; $this->processExecutor = $processExecutor; } @@ -32,7 +32,8 @@ class HhvmDetector self::$hhvmVersion = null; } - public function getVersion() { + public function getVersion() + { if (null !== self::$hhvmVersion) { return self::$hhvmVersion ?: null; } @@ -54,6 +55,7 @@ class HhvmDetector } } } + return self::$hhvmVersion; } } diff --git a/src/Composer/Platform/Runtime.php b/src/Composer/Platform/Runtime.php index baf450df1..82211ec88 100644 --- a/src/Composer/Platform/Runtime.php +++ b/src/Composer/Platform/Runtime.php @@ -19,7 +19,8 @@ class Runtime * @param class-string $class * @return bool */ - public function hasConstant($constant, $class = null) { + public function hasConstant($constant, $class = null) + { return defined(ltrim($class.'::'.$constant, ':')); } @@ -28,7 +29,8 @@ class Runtime * @param class-string $class * @return mixed */ - public function getConstant($constant, $class = null) { + public function getConstant($constant, $class = null) + { return constant(ltrim($class.'::'.$constant, ':')); } @@ -37,7 +39,8 @@ class Runtime * @param array $arguments * @return mixed */ - public function invoke($callable, array $arguments = array()) { + public function invoke($callable, array $arguments = array()) + { return call_user_func_array($callable, $arguments); } @@ -45,7 +48,8 @@ class Runtime * @param class-string $class * @return bool */ - public function hasClass($class) { + public function hasClass($class) + { return class_exists($class, false); } @@ -54,7 +58,8 @@ class Runtime * @param array $arguments * @return object */ - public function construct($class, array $arguments = array()) { + public function construct($class, array $arguments = array()) + { if (empty($arguments)) { return new $class; } diff --git a/src/Composer/Util/Version.php b/src/Composer/Platform/Version.php similarity index 98% rename from src/Composer/Util/Version.php rename to src/Composer/Platform/Version.php index 1907816c0..ab7cae0c4 100644 --- a/src/Composer/Util/Version.php +++ b/src/Composer/Platform/Version.php @@ -10,7 +10,7 @@ * file that was distributed with this source code. */ -namespace Composer\Util; +namespace Composer\Platform; /** * @author Lars Strojny diff --git a/src/Composer/Repository/PlatformRepository.php b/src/Composer/Repository/PlatformRepository.php index 899b177cf..850b40acb 100644 --- a/src/Composer/Repository/PlatformRepository.php +++ b/src/Composer/Repository/PlatformRepository.php @@ -19,10 +19,10 @@ use Composer\Package\PackageInterface; use Composer\Package\Version\VersionParser; use Composer\Platform\HhvmDetector; use Composer\Platform\Runtime; +use Composer\Platform\Version; use Composer\Plugin\PluginInterface; use Composer\Semver\Constraint\Constraint; use Composer\Util\Silencer; -use Composer\Util\Version; use Composer\XdebugHandler\XdebugHandler; /** @@ -156,12 +156,12 @@ class PlatformRepository extends ArrayRepository $info = $this->runtime->getExtensionInfo($name); // librabbitmq version => 0.9.0 - if (preg_match('/^librabbitmq version => (?.+)$/m', $info, $librabbitmqMatches)) { + if (preg_match('/^librabbitmq version => (?.+)$/im', $info, $librabbitmqMatches)) { $this->addLibrary($name.'-librabbitmq', $librabbitmqMatches['version'], 'AMQP librabbitmq version'); } // AMQP protocol version => 0-9-1 - if (preg_match('/^AMQP protocol version => (?.+)$/m', $info, $protocolMatches)) { + if (preg_match('/^AMQP protocol version => (?.+)$/im', $info, $protocolMatches)) { $this->addLibrary($name.'-protocol', str_replace('-', '.', $protocolMatches['version']), 'AMQP protocol version'); } break; @@ -170,7 +170,7 @@ class PlatformRepository extends ArrayRepository $info = $this->runtime->getExtensionInfo($name); // BZip2 Version => 1.0.6, 6-Sept-2010 - if (preg_match('/^BZip2 Version => (?.*),/m', $info, $matches)) { + if (preg_match('/^BZip2 Version => (?.*),/im', $info, $matches)) { $this->addLibrary($name, $matches['version']); } break; @@ -182,7 +182,7 @@ class PlatformRepository extends ArrayRepository $info = $this->runtime->getExtensionInfo($name); // SSL Version => OpenSSL/1.0.1t - if (preg_match('{^SSL Version => (?[^/]+)/(?.+)$}m', $info, $sslMatches)) { + if (preg_match('{^SSL Version => (?[^/]+)/(?.+)$}im', $info, $sslMatches)) { $library = strtolower($sslMatches['library']); if ($library === 'openssl') { $parsedVersion = Version::parseOpenssl($sslMatches['version'], $isFips); @@ -193,12 +193,12 @@ class PlatformRepository extends ArrayRepository } // libSSH Version => libssh2/1.4.3 - if (preg_match('{^libSSH Version => (?[^/]+)/(?.+?)(?:/.*)?$}m', $info, $sshMatches)) { + if (preg_match('{^libSSH Version => (?[^/]+)/(?.+?)(?:/.*)?$}im', $info, $sshMatches)) { $this->addLibrary($name.'-'.strtolower($sshMatches['library']), $sshMatches['version'], 'curl '.$sshMatches['library'].' version'); } // ZLib Version => 1.2.8 - if (preg_match('{^ZLib Version => (?.+)$}m', $info, $zlibMatches)) { + if (preg_match('{^ZLib Version => (?.+)$}im', $info, $zlibMatches)) { $this->addLibrary($name.'-zlib', $zlibMatches['version'], 'curl zlib version'); } break; @@ -207,14 +207,14 @@ class PlatformRepository extends ArrayRepository $info = $this->runtime->getExtensionInfo($name); // timelib version => 2018.03 - if (preg_match('/^timelib version => (?.+)$/m', $info, $timelibMatches)) { + if (preg_match('/^timelib version => (?.+)$/im', $info, $timelibMatches)) { $this->addLibrary($name.'-timelib', $timelibMatches['version'], 'date timelib version'); } // Timezone Database => internal - if (preg_match('/^Timezone Database => (?internal|external)$/m', $info, $zoneinfoSourceMatches)) { + if (preg_match('/^Timezone Database => (?internal|external)$/im', $info, $zoneinfoSourceMatches)) { $external = $zoneinfoSourceMatches['source'] === 'external'; - if (preg_match('/^"Olson" Timezone Database Version => (?.+?)(\.system)?$/m', $info, $zoneinfoMatches)) { + if (preg_match('/^"Olson" Timezone Database Version => (?.+?)(\.system)?$/im', $info, $zoneinfoMatches)) { // If the timezonedb is provided by ext/timezonedb, register that version as a replacement if ($external && in_array('timezonedb', $loadedExtensions, true)) { $this->addLibrary('timezonedb-zoneinfo', $zoneinfoMatches['version'], 'zoneinfo ("Olson") database for date (replaced by timezonedb)', array($name.'-zoneinfo')); @@ -229,7 +229,7 @@ class PlatformRepository extends ArrayRepository $info = $this->runtime->getExtensionInfo($name); // libmagic => 537 - if (preg_match('/^^libmagic => (?.+)$/m', $info, $magicMatches)) { + if (preg_match('/^libmagic => (?.+)$/im', $info, $magicMatches)) { $this->addLibrary($name.'-libmagic', $magicMatches['version'], 'fileinfo libmagic version'); } break; @@ -239,19 +239,19 @@ class PlatformRepository extends ArrayRepository $info = $this->runtime->getExtensionInfo($name); - if (preg_match('/^libJPEG Version => (?.+?)(?: compatible)?$/m', $info, $libjpegMatches)) { + if (preg_match('/^libJPEG Version => (?.+?)(?: compatible)?$/im', $info, $libjpegMatches)) { $this->addLibrary($name.'-libjpeg', Version::parseLibjpeg($libjpegMatches['version']), 'libjpeg version for gd'); } - if (preg_match('/^libPNG Version => (?.+)$/m', $info, $libpngMatches)) { + if (preg_match('/^libPNG Version => (?.+)$/im', $info, $libpngMatches)) { $this->addLibrary($name.'-libpng', $libpngMatches['version'], 'libpng version for gd'); } - if (preg_match('/^FreeType Version => (?.+)$/m', $info, $freetypeMatches)) { + if (preg_match('/^FreeType Version => (?.+)$/im', $info, $freetypeMatches)) { $this->addLibrary($name.'-freetype', $freetypeMatches['version'], 'freetype version for gd'); } - if (preg_match('/^libXpm Version => (?\d+)$/m', $info, $libxpmMatches)) { + if (preg_match('/^libXpm Version => (?\d+)$/im', $info, $libxpmMatches)) { $this->addLibrary($name.'-libxpm', Version::convertLibxpmVersionId($libxpmMatches['versionId']), 'libxpm version for gd'); } @@ -272,16 +272,16 @@ class PlatformRepository extends ArrayRepository // Truthy check is for testing only so we can make the condition fail if ($this->runtime->hasConstant('INTL_ICU_VERSION')) { $this->addLibrary('icu', $this->runtime->getConstant('INTL_ICU_VERSION'), $description); - } elseif (preg_match('/^ICU version => (?.+)$/m', $info, $matches)) { + } elseif (preg_match('/^ICU version => (?.+)$/im', $info, $matches)) { $this->addLibrary('icu', $matches['version'], $description); } // ICU TZData version => 2019c - if (preg_match('/^ICU TZData version => (?.*)$/m', $info, $zoneinfoMatches)) { + if (preg_match('/^ICU TZData version => (?.*)$/im', $info, $zoneinfoMatches)) { $this->addLibrary('icu-zoneinfo', Version::parseZoneinfoVersion($zoneinfoMatches['version']), 'zoneinfo ("Olson") database for icu'); } - # Add a separate version for the CLDR library version + // Add a separate version for the CLDR library version if ($this->runtime->hasClass('ResourceBundle')) { $cldrVersion = $this->runtime->invoke(array('ResourceBundle', 'create'), array('root', 'ICUDATA', false))->get('Version'); $this->addLibrary('icu-cldr', $cldrVersion, 'ICU CLDR project version'); @@ -308,7 +308,7 @@ class PlatformRepository extends ArrayRepository case 'ldap': $info = $this->runtime->getExtensionInfo($name); - if (preg_match('/^Vendor Version => (?\d+)$/m', $info, $matches) && preg_match('/^Vendor Name => (?.+)$/m', $info, $vendorMatches)) { + if (preg_match('/^Vendor Version => (?\d+)$/im', $info, $matches) && preg_match('/^Vendor Name => (?.+)$/im', $info, $vendorMatches)) { $this->addLibrary($name.'-'.strtolower($vendorMatches['vendor']), Version::convertOpenldapVersionId($matches['versionId']), $vendorMatches['vendor'].' version of ldap'); } break; @@ -326,7 +326,7 @@ class PlatformRepository extends ArrayRepository $info = $this->runtime->getExtensionInfo($name); // libmbfl version => 1.3.2 - if (preg_match('/^libmbfl version => (?.+)$/m', $info, $libmbflMatches)) { + if (preg_match('/^libmbfl version => (?.+)$/im', $info, $libmbflMatches)) { $this->addLibrary($name.'-libmbfl', $libmbflMatches['version'], 'mbstring libmbfl version'); } @@ -335,7 +335,7 @@ class PlatformRepository extends ArrayRepository // Multibyte regex (oniguruma) version => 5.9.5 // oniguruma version => 6.9.0 - } elseif (preg_match('/^(?:oniguruma|Multibyte regex \(oniguruma\)) version => (?.+)$/m', $info, $onigurumaMatches)) { + } elseif (preg_match('/^(?:oniguruma|Multibyte regex \(oniguruma\)) version => (?.+)$/im', $info, $onigurumaMatches)) { $this->addLibrary($name.'-oniguruma', $onigurumaMatches['version'], 'mbstring oniguruma version'); } @@ -345,7 +345,7 @@ class PlatformRepository extends ArrayRepository $info = $this->runtime->getExtensionInfo($name); // libmemcached version => 1.0.18 - if (preg_match('/^libmemcached version => (?.+)$/m', $info, $matches)) { + if (preg_match('/^libmemcached version => (?.+)$/im', $info, $matches)) { $this->addLibrary($name.'-libmemcached', $matches['version'], 'libmemcached version'); } break; @@ -364,7 +364,7 @@ class PlatformRepository extends ArrayRepository $info = $this->runtime->getExtensionInfo($name); // PCRE Unicode Version => 12.1.0 - if (preg_match('/^PCRE Unicode Version => (?.+)$/m', $info, $pcreUnicodeMatches)) { + if (preg_match('/^PCRE Unicode Version => (?.+)$/im', $info, $pcreUnicodeMatches)) { $this->addLibrary($name.'-unicode', $pcreUnicodeMatches['version'], 'PCRE Unicode version support'); } @@ -382,11 +382,11 @@ class PlatformRepository extends ArrayRepository case 'mongodb': $info = $this->runtime->getExtensionInfo($name); - if (preg_match('/^libmongoc bundled version => (?.+)$/m', $info, $libmongocMatches)) { + if (preg_match('/^libmongoc bundled version => (?.+)$/im', $info, $libmongocMatches)) { $this->addLibrary($name.'-libmongoc', $libmongocMatches['version'], 'libmongoc version of mongodb'); } - if (preg_match('/^libbson bundled version => (?.+)$/m', $info, $libbsonMatches)) { + if (preg_match('/^libbson bundled version => (?.+)$/im', $info, $libbsonMatches)) { $this->addLibrary($name.'-libbson', $libbsonMatches['version'], 'libbson version of mongodb'); } break; @@ -395,7 +395,7 @@ class PlatformRepository extends ArrayRepository case 'pdo_pgsql': $info = $this->runtime->getExtensionInfo($name); - if (preg_match('/^PostgreSQL\(libpq\) Version => (?.*)$/m', $info, $matches)) { + if (preg_match('/^PostgreSQL\(libpq\) Version => (?.*)$/im', $info, $matches)) { $this->addLibrary($name.'-libpq', $matches['version'], 'libpq for '.$name); } break; @@ -409,7 +409,7 @@ class PlatformRepository extends ArrayRepository case 'pdo_sqlite': $info = $this->runtime->getExtensionInfo($name); - if (preg_match('/^SQLite Library => (?.+)$/m', $info, $matches)) { + if (preg_match('/^SQLite Library => (?.+)$/im', $info, $matches)) { $this->addLibrary($name.'-sqlite', $matches['version']); } break; @@ -417,7 +417,7 @@ class PlatformRepository extends ArrayRepository case 'ssh2': $info = $this->runtime->getExtensionInfo($name); - if (preg_match('/^libssh2 version => (?.+)$/m', $info, $matches)) { + if (preg_match('/^libssh2 version => (?.+)$/im', $info, $matches)) { $this->addLibrary($name.'-libssh2', $matches['version']); } break; @@ -426,7 +426,7 @@ class PlatformRepository extends ArrayRepository $this->addLibrary('libxslt', $this->runtime->getConstant('LIBXSLT_DOTTED_VERSION'), null, array('xsl')); $info = $this->runtime->getExtensionInfo('xsl'); - if (preg_match('/^libxslt compiled against libxml Version => (?.+)$/m', $info, $matches)) { + if (preg_match('/^libxslt compiled against libxml Version => (?.+)$/im', $info, $matches)) { $this->addLibrary('libxslt-libxml', $matches['version'], 'libxml version libxslt is compiled against'); } break; @@ -434,7 +434,7 @@ class PlatformRepository extends ArrayRepository case 'yaml': $info = $this->runtime->getExtensionInfo('yaml'); - if (preg_match('/^LibYAML Version => (?.+)$/m', $info, $matches)) { + if (preg_match('/^LibYAML Version => (?.+)$/im', $info, $matches)) { $this->addLibrary($name.'-libyaml', $matches['version'], 'libyaml version of yaml'); } break; @@ -450,7 +450,7 @@ class PlatformRepository extends ArrayRepository $this->addLibrary($name, $this->runtime->getConstant('ZLIB_VERSION')); // Linked Version => 1.2.8 - } elseif (preg_match('/^Linked Version => (?.+)$/m', $this->runtime->getExtensionInfo($name), $matches)) { + } elseif (preg_match('/^Linked Version => (?.+)$/im', $this->runtime->getExtensionInfo($name), $matches)) { $this->addLibrary($name, $matches['version']); } break; diff --git a/tests/Composer/Test/Platform/HhvmDetectorTest.php b/tests/Composer/Test/Platform/HhvmDetectorTest.php index 3e7e63228..600ef7193 100644 --- a/tests/Composer/Test/Platform/HhvmDetectorTest.php +++ b/tests/Composer/Test/Platform/HhvmDetectorTest.php @@ -28,7 +28,8 @@ class HhvmDetectorTest extends TestCase $this->hhvmDetector->reset(); } - public function testHHVMVersionWhenExecutingInHHVM() { + public function testHHVMVersionWhenExecutingInHHVM() + { if (!defined('HHVM_VERSION_ID')) { self::markTestSkipped('Not running with HHVM'); return; @@ -37,7 +38,8 @@ class HhvmDetectorTest extends TestCase self::assertSame(self::versionIdToVersion(), $version); } - public function testHHVMVersionWhenExecutingInPHP() { + public function testHHVMVersionWhenExecutingInPHP() + { if (defined('HHVM_VERSION_ID')) { self::markTestSkipped('Running with HHVM'); return; diff --git a/tests/Composer/Test/Util/VersionTest.php b/tests/Composer/Test/Platform/VersionTest.php similarity index 98% rename from tests/Composer/Test/Util/VersionTest.php rename to tests/Composer/Test/Platform/VersionTest.php index 907e1e472..5d5452143 100644 --- a/tests/Composer/Test/Util/VersionTest.php +++ b/tests/Composer/Test/Platform/VersionTest.php @@ -10,9 +10,9 @@ * file that was distributed with this source code. */ -namespace Composer\Test\Util; +namespace Composer\Test\Platform; -use Composer\Util\Version; +use Composer\Platform\Version; use Composer\Test\TestCase; /**