/** * Checks PHP version * * @return array */ public function checkPhpVersion() { try { $requiredVersion = $this->composerInformation->getRequiredPhpVersion(); } catch (\Exception $e) { return [ 'responseType' => ResponseTypeInterface::RESPONSE_TYPE_ERROR, 'data' => [ 'error' => 'phpVersionError', 'message' => 'Cannot determine required PHP version: ' . $e->getMessage() ], ]; } $multipleConstraints = $this->versionParser->parseConstraints($requiredVersion); try { $normalizedPhpVersion = $this->versionParser->normalize(PHP_VERSION); } catch (\UnexpectedValueException $e) { $prettyVersion = preg_replace('#^([^~+-]+).*$#', '$1', PHP_VERSION); $normalizedPhpVersion = $this->versionParser->normalize($prettyVersion); } $currentPhpVersion = $this->versionParser->parseConstraints($normalizedPhpVersion); $responseType = ResponseTypeInterface::RESPONSE_TYPE_SUCCESS; if (!$multipleConstraints->matches($currentPhpVersion)) { $responseType = ResponseTypeInterface::RESPONSE_TYPE_ERROR; } return [ 'responseType' => $responseType, 'data' => [ 'required' => $requiredVersion, 'current' => PHP_VERSION, ], ]; }
protected function initialize() { parent::initialize(); $versionParser = new VersionParser(); try { $prettyVersion = PHP_VERSION; $version = $versionParser->normalize($prettyVersion); } catch (\UnexpectedValueException $e) { $prettyVersion = preg_replace('#^(.+?)(-.+)?$#', '$1', PHP_VERSION); $version = $versionParser->normalize($prettyVersion); } $php = new MemoryPackage('php', $version, $prettyVersion); $php->setDescription('The PHP interpreter'); 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); } $ext = new MemoryPackage('ext-' . $name, $version, $prettyVersion); $ext->setDescription('The ' . $name . ' PHP extension'); parent::addPackage($ext); } }
protected function prepare() { if (Type::determinePickle($this->path, $matches) < 1) { throw new \Exception('Not a pickle git URI'); } $this->name = $matches['package']; $extension = $this->fetchPackageJson(); $versionParser = new VersionParser(); if ($matches['version'] == '') { $versions = array_keys($extension['packages'][$this->name]); if (count($versions) > 1) { $versionToUse = $versions[1]; } else { $versionToUse = $versions[0]; } } else { $versionConstraints = $versionParser->parseConstraints($matches['version']); /* versions are sorted decreasing */ foreach ($extension['packages'][$this->name] as $version => $release) { $constraint = new VersionConstraint('=', $versionParser->normalize($version)); if ($versionConstraints->matches($constraint)) { $versionToUse = $version; break; } } } $package = $extension['packages'][$this->name][$versionToUse]; $this->version = $versionToUse; $this->normalizedVersion = $versionParser->normalize($versionToUse); $this->name = $matches['package']; $this->prettyVersion = $this->version; $this->url = $package['source']['url']; $this->reference = $package['source']['reference']; $this->type = $package['source']['type']; }
/** * Tests memory package marshalling/serialization semantics * @dataProvider providerVersioningSchemes */ public function testMemoryPackageHasExpectedMarshallingSemantics($name, $version) { $versionParser = new VersionParser(); $normVersion = $versionParser->normalize($version); $package = new MemoryPackage($name, $normVersion, $version); $this->assertEquals(strtolower($name) . '-' . $normVersion, (string) $package); }
/** * @param PackageInterface $package * @param bool $allowDevMaster * * @return \string[] */ public function validatePackage(PackageInterface $package, $allowDevMaster = false) { $errors = []; $versionParser = new VersionParser(); /** @noinspection ExceptionsAnnotatingAndHandlingInspection */ $devMaster = new Constraint('==', $versionParser->normalize('dev-master')); foreach ($package->getRequires() as $link) { $linkConstraint = $link->getConstraint(); if (preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $link->getTarget())) { continue; } if ($linkConstraint->matches($devMaster)) { if ($allowDevMaster) { continue; } $errors[] = sprintf('Package "%s" is required with branch constraint %s', $link->getTarget(), $linkConstraint->getPrettyString()); } $constraints = [$linkConstraint]; if ($linkConstraint instanceof MultiConstraint) { $constraints = (new ConstraintAccessor($linkConstraint))->getConstraints(); } foreach ($constraints as $constraint) { if ('dev-' === substr($constraint->getPrettyString(), 0, 4)) { $errors[] = sprintf('Package "%s" is required with branch constraint %s', $link->getTarget(), $linkConstraint->getPrettyString()); } } } return $errors; }
/** * {@inheritDoc} */ public function getMinimalPackages() { if (isset($this->minimalPackages)) { return $this->minimalPackages; } if (null === $this->rawData) { $this->rawData = $this->loadDataFromServer(); } $this->minimalPackages = array(); $versionParser = new VersionParser(); foreach ($this->rawData as $package) { $version = !empty($package['version_normalized']) ? $package['version_normalized'] : $versionParser->normalize($package['version']); $data = array('name' => strtolower($package['name']), 'repo' => $this, 'version' => $version, 'raw' => $package); if (!empty($package['replace'])) { $data['replace'] = $package['replace']; } if (!empty($package['provide'])) { $data['provide'] = $package['provide']; } // add branch aliases if ($aliasNormalized = $this->loader->getBranchAlias($package)) { $data['alias'] = preg_replace('{(\\.9{7})+}', '.x', $aliasNormalized); $data['alias_normalized'] = $aliasNormalized; } $this->minimalPackages[] = $data; } return $this->minimalPackages; }
/** * Return true if $version matches $constraint (expressed as a Composer constraint string) * * @param string $version * @param string $constraint * @return bool */ public function isVersionMatching($version, $constraint) { $versionParser = new VersionParser(); $normalizedVersion = $versionParser->normalize($version); $versionAsContraint = $versionParser->parseConstraints($normalizedVersion); $linkConstraint = $versionParser->parseConstraints($constraint); return $linkConstraint->matches($versionAsContraint); }
public function updateVersion() { /* Be sure package root is set before! */ $version = new Header\Version($this); $parser = new VersionParser(); $this->version = $parser->normalize($version); $this->prettyVersion = (string) $version; }
/** * Check if the version must be skipped. * * @param AssetTypeInterface $assetType The asset type * @param string $name The composer package name * @param string $version The version * * @return bool */ public function skip(AssetTypeInterface $assetType, $name, $version) { if (!isset($this->requires[$name])) { return false; } /* @var Link $require */ $require = $this->requires[$name]; try { $cVersion = $assetType->getVersionConverter()->convertVersion($version); $normalizedVersion = $this->versionParser->normalize($cVersion); return !$this->satisfy($require, $normalizedVersion); } catch (\Exception $ex) { return true; } }
/** * Normalize PHP Version * * @param string $version * @return string */ private function getNormalizedCurrentPhpVersion($version) { try { $normalizedPhpVersion = $this->versionParser->normalize($version); } catch (\UnexpectedValueException $e) { $prettyVersion = preg_replace('#^([^~+-]+).*$#', '$1', $version); $normalizedPhpVersion = $this->versionParser->normalize($prettyVersion); } return $normalizedPhpVersion; }
/** * {@inheritDoc} */ public function findPackage($name, $version) { // normalize version & name $versionParser = new VersionParser(); $version = $versionParser->normalize($version); $name = strtolower($name); foreach ($this->getPackages() as $package) { if ($name === $package->getName() && $version === $package->getVersion()) { return $package; } } }
public static function createComposerInMemoryPackage($targetDir, $version) { $url = self::getURL($version); $versionParser = new VersionParser(); $normVersion = $versionParser->normalize($version); $package = new Package(self::PHANTOMJS_NAME, $normVersion, $version); $package->setTargetDir($targetDir); $package->setInstallationSource('dist'); $package->setDistType(pathinfo($url, PATHINFO_EXTENSION) === 'zip' ? 'zip' : 'tar'); // set zip, tarball $package->setDistUrl($url); return $package; }
public function testWhatProvides() { $repo = $this->getMockBuilder('Composer\\Repository\\ComposerRepository')->disableOriginalConstructor()->setMethods(array('fetchFile'))->getMock(); $cache = $this->getMockBuilder('Composer\\Cache')->disableOriginalConstructor()->getMock(); $cache->expects($this->any())->method('sha256')->will($this->returnValue(false)); $properties = array('cache' => $cache, 'loader' => new ArrayLoader(), 'providerListing' => array('p/a.json' => array('sha256' => 'xxx'))); foreach ($properties as $property => $value) { $ref = new \ReflectionProperty($repo, $property); $ref->setAccessible(true); $ref->setValue($repo, $value); } $repo->expects($this->any())->method('fetchFile')->will($this->returnValue(array('packages' => array(array(array('uid' => 1, 'name' => 'a', 'version' => 'dev-master', 'extra' => array('branch-alias' => array('dev-master' => '1.0.x-dev')))), array(array('uid' => 2, 'name' => 'a', 'version' => 'dev-develop', 'extra' => array('branch-alias' => array('dev-develop' => '1.1.x-dev')))), array(array('uid' => 3, 'name' => 'a', 'version' => '0.6')))))); $pool = $this->getMock('Composer\\DependencyResolver\\Pool'); $pool->expects($this->any())->method('isPackageAcceptable')->will($this->returnValue(true)); $versionParser = new VersionParser(); $repo->setRootAliases(array('a' => array($versionParser->normalize('0.6') => array('alias' => 'dev-feature', 'alias_normalized' => $versionParser->normalize('dev-feature')), $versionParser->normalize('1.1.x-dev') => array('alias' => '1.0', 'alias_normalized' => $versionParser->normalize('1.0'))))); $packages = $repo->whatProvides($pool, 'a'); $this->assertCount(7, $packages); $this->assertEquals(array('1', '1-alias', '2', '2-alias', '2-root', '3', '3-root'), array_keys($packages)); $this->assertInstanceOf('Composer\\Package\\AliasPackage', $packages['2-root']); $this->assertSame($packages['2'], $packages['2-root']->getAliasOf()); $this->assertSame($packages['2'], $packages['2-alias']->getAliasOf()); }
public function findPackages($name, $version = null) { $name = strtolower($name); if (null !== $version) { $versionParser = new VersionParser(); $version = $versionParser->normalize($version); } $packages = array(); foreach ($this->getPackages() as $package) { if ($package->getName() === $name && (null === $version || $version === $package->getVersion())) { $packages[] = $package; } } return $packages; }
/** * @dataProvider getRecommendedRequireVersionPackages */ public function testFindRecommendedRequireVersion($prettyVersion, $isDev, $stability, $expectedVersion, $branchAlias = null) { $pool = $this->createMockPool(); $versionSelector = new VersionSelector($pool); $versionParser = new VersionParser(); $package = $this->getMock('\\Composer\\Package\\PackageInterface'); $package->expects($this->any())->method('getPrettyVersion')->will($this->returnValue($prettyVersion)); $package->expects($this->any())->method('getVersion')->will($this->returnValue($versionParser->normalize($prettyVersion))); $package->expects($this->any())->method('isDev')->will($this->returnValue($isDev)); $package->expects($this->any())->method('getStability')->will($this->returnValue($stability)); $branchAlias = $branchAlias === null ? array() : array('branch-alias' => array($prettyVersion => $branchAlias)); $package->expects($this->any())->method('getExtra')->will($this->returnValue($branchAlias)); $recommended = $versionSelector->findRecommendedRequireVersion($package); // assert that the recommended version is what we expect $this->assertEquals($expectedVersion, $recommended); }
/** * Installation package * * @param Composer $composer */ public function install(Composer $composer) { $this->init(); /* Create Composer in-memory package */ $versionParser = new VersionParser(); $normVersion = $versionParser->normalize($this->version); $package = new Package($this->name, $normVersion, $this->version); $package->setInstallationSource('dist'); $package->setDistUrl($this->url); $package->setDistType($this->distType); $package->setTargetDir($this->targetDir); /* Download the Archive */ $downloadManager = $composer->getDownloadManager(); $downloadManager->download($package, $this->targetDir, false); /* Copy binary to the "bin" file */ $binDir = $composer->getConfig()->get('bin-dir'); $this->copyToBinFolder($binDir); }
/** * Validates the tag. * * @param string $tag * @param AssetTypeInterface $assetType * @param VersionParser|null $parser * * @return false|string */ public static function validateTag($tag, AssetTypeInterface $assetType, VersionParser $parser = null) { if (in_array($tag, array('master', 'trunk', 'default'))) { return false; } if (null === $parser) { $parser = new VersionParser(); } try { $tag = $assetType->getVersionConverter()->convertVersion($tag); $tag = $parser->normalize($tag); } catch (\Exception $e) { $tag = false; } return $tag; }
private function guessSvnVersion(array $packageConfig, $path) { SvnUtil::cleanEnv(); // try to fetch current version from svn if (0 === $this->process->execute('svn info --xml', $output, $path)) { $trunkPath = isset($packageConfig['trunk-path']) ? preg_quote($packageConfig['trunk-path'], '#') : 'trunk'; $branchesPath = isset($packageConfig['branches-path']) ? preg_quote($packageConfig['branches-path'], '#') : 'branches'; $tagsPath = isset($packageConfig['tags-path']) ? preg_quote($packageConfig['tags-path'], '#') : 'tags'; $urlPattern = '#<url>.*/(' . $trunkPath . '|(' . $branchesPath . '|' . $tagsPath . ')/(.*))</url>#'; if (preg_match($urlPattern, $output, $matches)) { if (isset($matches[2]) && ($branchesPath === $matches[2] || $tagsPath === $matches[2])) { // we are in a branches path $version = $this->versionParser->normalizeBranch($matches[3]); if ('9999999-dev' === $version) { $version = 'dev-' . $matches[3]; } return $version; } return $this->versionParser->normalize(trim($matches[1])); } } }
/** * Operating system dependend installation of PhantomJS */ public static function installPhantomJS(Event $event) { $composer = $event->getComposer(); $version = self::getVersion($composer); $url = self::getURL($version); $binDir = $composer->getConfig()->get('bin-dir'); // the installation folder depends on the vendor-dir (default prefix is './vendor') $targetDir = $composer->getConfig()->get('vendor-dir') . self::PHANTOMJS_TARGETDIR; // Create Composer In-Memory Package $versionParser = new VersionParser(); $normVersion = $versionParser->normalize($version); $package = new Package(self::PHANTOMJS_NAME, $normVersion, $version); $package->setTargetDir($targetDir); $package->setInstallationSource('dist'); $package->setDistType(pathinfo($url, PATHINFO_EXTENSION) === 'zip' ? 'zip' : 'tar'); // set zip, tarball $package->setDistUrl($url); // Download the Archive $downloadManager = $composer->getDownloadManager(); $downloadManager->download($package, $targetDir, false); // Copy only the PhantomJS binary from the installation "target dir" to the "bin" folder self::copyPhantomJsBinaryToBinFolder($targetDir, $binDir); }
/** * Operating system dependend installation of CasperJS */ public static function install(Event $event) { //Install PhantomJs before CasperJs \PhantomInstaller\Installer::installPhantomJS($event); $composer = $event->getComposer(); $version = self::getVersion($composer); $url = self::getURL($version); $binDir = $composer->getConfig()->get('bin-dir'); // the installation folder depends on the vendor-dir (default prefix is './vendor') $targetDir = $composer->getConfig()->get('vendor-dir') . self::CASPERJS_TARGETDIR; // Create Composer In-Memory Package $versionParser = new VersionParser(); $normVersion = $versionParser->normalize($version); $package = new Package(self::CASPERJS_NAME, $normVersion, $version); $package->setTargetDir($targetDir); $package->setInstallationSource('dist'); $package->setDistType('zip'); $package->setDistUrl($url); // Download the Archive $downloadManager = $composer->getDownloadManager(); $downloadManager->download($package, $targetDir, false); // Create CasperJS launcher in the "bin" folder self::createCasperJsBinaryToBinFolder($targetDir, $binDir); }
/** * Operating system dependend installation of PhantomJS */ public static function installPhantomJS(Event $event) { $composer = $event->getComposer(); $version = self::getVersion($composer); $url = self::getURL($version); // Create Composer In-Memory Package $versionParser = new VersionParser(); $normVersion = $versionParser->normalize($version); $package = new Package(self::PHANTOMJS_NAME, $normVersion, $version); $package->setTargetDir(self::PHANTOMJS_TARGETDIR); $package->setInstallationSource('dist'); $package->setDistType(pathinfo($url, PATHINFO_EXTENSION) === 'zip' ? 'zip' : 'tar'); // set zip, tarball $package->setDistUrl($url); // Download the Archive //$io = $event->getIO(); //$io->write('<info>Fetching PhantomJS v'.$version.'</info>'); $downloadManager = $composer->getDownloadManager(); $downloadManager->download($package, self::PHANTOMJS_TARGETDIR, false); // Copy all PhantomJS files to "bin" folder // self::recursiveCopy(self::PHANTOMJS_TARGETDIR, './bin'); // Copy only the PhantomJS binary to the "bin" folder self::copyPhantomJsBinaryToBinFolder($composer); }
/** * @Route( * "/packages/{name}/stats/{version}.json", * name="version_stats", * requirements={"name"="[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?", "version"=".+?"} * ) */ public function versionStatsAction(Request $req, Package $package, $version) { $normalizer = new VersionParser(); $normVersion = $normalizer->normalize($version); $version = $this->getDoctrine()->getRepository('PackagistWebBundle:Version')->findOneBy(['package' => $package, 'normalizedVersion' => $normVersion]); if (!$version) { throw new NotFoundHttpException(); } return $this->overallStatsAction($req, $package, $version); }
/** * @dataProvider failingNormalizedVersions * @expectedException UnexpectedValueException */ public function testNormalizeFails($input) { $parser = new VersionParser(); $parser->normalize($input); }
/** * Builds CompletePackages from PEAR package definition data. * * @param ChannelInfo $channelInfo * @param VersionParser $versionParser * @return CompletePackage */ private function buildComposerPackages(ChannelInfo $channelInfo, VersionParser $versionParser) { $result = array(); foreach ($channelInfo->getPackages() as $packageDefinition) { foreach ($packageDefinition->getReleases() as $version => $releaseInfo) { try { $normalizedVersion = $versionParser->normalize($version); } catch (\UnexpectedValueException $e) { if ($this->io->isVerbose()) { $this->io->writeError('Could not load ' . $packageDefinition->getPackageName() . ' ' . $version . ': ' . $e->getMessage()); } continue; } $composerPackageName = $this->buildComposerPackageName($packageDefinition->getChannelName(), $packageDefinition->getPackageName()); // distribution url must be read from /r/{packageName}/{version}.xml::/r/g:text() // but this location is 'de-facto' standard $urlBits = parse_url($this->url); $scheme = isset($urlBits['scheme']) && 'https' === $urlBits['scheme'] && extension_loaded('openssl') ? 'https' : 'http'; $distUrl = "{$scheme}://{$packageDefinition->getChannelName()}/get/{$packageDefinition->getPackageName()}-{$version}.tgz"; $requires = array(); $suggests = array(); $conflicts = array(); $replaces = array(); // alias package only when its channel matches repository channel, // cause we've know only repository channel alias if ($channelInfo->getName() == $packageDefinition->getChannelName()) { $composerPackageAlias = $this->buildComposerPackageName($channelInfo->getAlias(), $packageDefinition->getPackageName()); $aliasConstraint = new VersionConstraint('==', $normalizedVersion); $replaces[] = new Link($composerPackageName, $composerPackageAlias, $aliasConstraint, 'replaces', (string) $aliasConstraint); } // alias package with user-specified prefix. it makes private pear channels looks like composer's. if (!empty($this->vendorAlias) && ($this->vendorAlias != 'pear-' . $channelInfo->getAlias() || $channelInfo->getName() != $packageDefinition->getChannelName())) { $composerPackageAlias = "{$this->vendorAlias}/{$packageDefinition->getPackageName()}"; $aliasConstraint = new VersionConstraint('==', $normalizedVersion); $replaces[] = new Link($composerPackageName, $composerPackageAlias, $aliasConstraint, 'replaces', (string) $aliasConstraint); } foreach ($releaseInfo->getDependencyInfo()->getRequires() as $dependencyConstraint) { $dependencyPackageName = $this->buildComposerPackageName($dependencyConstraint->getChannelName(), $dependencyConstraint->getPackageName()); $constraint = $versionParser->parseConstraints($dependencyConstraint->getConstraint()); $link = new Link($composerPackageName, $dependencyPackageName, $constraint, $dependencyConstraint->getType(), $dependencyConstraint->getConstraint()); switch ($dependencyConstraint->getType()) { case 'required': $requires[] = $link; break; case 'conflicts': $conflicts[] = $link; break; case 'replaces': $replaces[] = $link; break; } } foreach ($releaseInfo->getDependencyInfo()->getOptionals() as $group => $dependencyConstraints) { foreach ($dependencyConstraints as $dependencyConstraint) { $dependencyPackageName = $this->buildComposerPackageName($dependencyConstraint->getChannelName(), $dependencyConstraint->getPackageName()); $suggests[$group . '-' . $dependencyPackageName] = $dependencyConstraint->getConstraint(); } } $package = new CompletePackage($composerPackageName, $normalizedVersion, $version); $package->setType('pear-library'); $package->setDescription($packageDefinition->getDescription()); $package->setLicense(array($packageDefinition->getLicense())); $package->setDistType('file'); $package->setDistUrl($distUrl); $package->setAutoload(array('classmap' => array(''))); $package->setIncludePaths(array('/')); $package->setRequires($requires); $package->setConflicts($conflicts); $package->setSuggests($suggests); $package->setReplaces($replaces); $result[] = $package; } } return $result; }
protected function initialize() { parent::initialize(); $versionParser = new VersionParser(); $prettyVersion = PluginInterface::PLUGIN_API_VERSION; $version = $versionParser->normalize($prettyVersion); $composerPluginApi = new CompletePackage('composer-plugin-api', $version, $prettyVersion); $composerPluginApi->setDescription('The Composer Plugin API'); parent::addPackage($composerPluginApi); try { $prettyVersion = PHP_VERSION; $version = $versionParser->normalize($prettyVersion); } catch (\UnexpectedValueException $e) { $prettyVersion = preg_replace('#^([^~+-]+).*$#', '$1', PHP_VERSION); $version = $versionParser->normalize($prettyVersion); } $php = new CompletePackage('php', $version, $prettyVersion); $php->setDescription('The PHP interpreter'); parent::addPackage($php); if (PHP_INT_SIZE === 8) { $php64 = new CompletePackage('php-64bit', $version, $prettyVersion); $php64->setDescription('The PHP interpreter (64bit)'); parent::addPackage($php64); } $loadedExtensions = get_loaded_extensions(); foreach ($loadedExtensions 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); } $packageName = $this->buildPackageName($name); $ext = new CompletePackage($packageName, $version, $prettyVersion); $ext->setDescription('The ' . $name . ' PHP extension'); parent::addPackage($ext); } foreach ($loadedExtensions as $name) { $prettyVersion = null; switch ($name) { case 'curl': $curlVersion = curl_version(); $prettyVersion = $curlVersion['version']; break; case 'iconv': $prettyVersion = ICONV_VERSION; break; case 'intl': $name = 'ICU'; if (defined('INTL_ICU_VERSION')) { $prettyVersion = INTL_ICU_VERSION; } else { $reflector = new \ReflectionExtension('intl'); ob_start(); $reflector->info(); $output = ob_get_clean(); preg_match('/^ICU version => (.*)$/m', $output, $matches); $prettyVersion = $matches[1]; } break; case 'libxml': $prettyVersion = LIBXML_DOTTED_VERSION; break; case 'openssl': $prettyVersion = preg_replace_callback('{^(?:OpenSSL\\s*)?([0-9.]+)([a-z]?).*}', function ($match) { return $match[1] . (empty($match[2]) ? '' : '.' . (ord($match[2]) - 96)); }, OPENSSL_VERSION_TEXT); break; case 'pcre': $prettyVersion = preg_replace('{^(\\S+).*}', '$1', PCRE_VERSION); break; case 'uuid': $prettyVersion = phpversion('uuid'); break; case 'xsl': $prettyVersion = LIBXSLT_DOTTED_VERSION; break; default: continue 2; } try { $version = $versionParser->normalize($prettyVersion); } catch (\UnexpectedValueException $e) { continue; } $lib = new CompletePackage('lib-' . $name, $version, $prettyVersion); $lib->setDescription('The ' . $name . ' PHP library'); parent::addPackage($lib); } if (defined('HHVM_VERSION')) { try { $prettyVersion = HHVM_VERSION; $version = $versionParser->normalize($prettyVersion); } catch (\UnexpectedValueException $e) { $prettyVersion = preg_replace('#^([^~+-]+).*$#', '$1', HHVM_VERSION); $version = $versionParser->normalize($prettyVersion); } $hhvm = new CompletePackage('hhvm', $version, $prettyVersion); $hhvm->setDescription('The HHVM Runtime (64bit)'); parent::addPackage($hhvm); } }
protected function initialize() { parent::initialize(); $versionParser = new VersionParser(); // Add each of the override versions as options. // Later we might even replace the extensions instead. foreach ($this->overrides as $override) { // Check that it's a platform package. if (!preg_match(self::PLATFORM_PACKAGE_REGEX, $override['name'])) { throw new \InvalidArgumentException('Invalid platform package name in config.platform: ' . $override['name']); } $version = $versionParser->normalize($override['version']); $package = new CompletePackage($override['name'], $version, $override['version']); $package->setDescription('Overridden virtual platform package ' . $override['name']); parent::addPackage($package); } $prettyVersion = PluginInterface::PLUGIN_API_VERSION; $version = $versionParser->normalize($prettyVersion); $composerPluginApi = new CompletePackage('composer-plugin-api', $version, $prettyVersion); $composerPluginApi->setDescription('The Composer Plugin API'); $this->addPackage($composerPluginApi); try { $prettyVersion = PHP_VERSION; $version = $versionParser->normalize($prettyVersion); } catch (\UnexpectedValueException $e) { $prettyVersion = preg_replace('#^([^~+-]+).*$#', '$1', PHP_VERSION); $version = $versionParser->normalize($prettyVersion); } $php = new CompletePackage('php', $version, $prettyVersion); $php->setDescription('The PHP interpreter'); $this->addPackage($php); if (PHP_INT_SIZE === 8) { $php64 = new CompletePackage('php-64bit', $version, $prettyVersion); $php64->setDescription('The PHP interpreter (64bit)'); $this->addPackage($php64); } $loadedExtensions = get_loaded_extensions(); // Extensions scanning foreach ($loadedExtensions 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); } $packageName = $this->buildPackageName($name); $ext = new CompletePackage($packageName, $version, $prettyVersion); $ext->setDescription('The ' . $name . ' PHP extension'); $this->addPackage($ext); } // 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) { $prettyVersion = null; switch ($name) { case 'curl': $curlVersion = curl_version(); $prettyVersion = $curlVersion['version']; break; case 'iconv': $prettyVersion = ICONV_VERSION; break; case 'intl': $name = 'ICU'; if (defined('INTL_ICU_VERSION')) { $prettyVersion = INTL_ICU_VERSION; } else { $reflector = new \ReflectionExtension('intl'); ob_start(); $reflector->info(); $output = ob_get_clean(); preg_match('/^ICU version => (.*)$/m', $output, $matches); $prettyVersion = $matches[1]; } break; case 'libxml': $prettyVersion = LIBXML_DOTTED_VERSION; break; case 'openssl': $prettyVersion = preg_replace_callback('{^(?:OpenSSL\\s*)?([0-9.]+)([a-z]?).*}', function ($match) { return $match[1] . (empty($match[2]) ? '' : '.' . (ord($match[2]) - 96)); }, OPENSSL_VERSION_TEXT); break; case 'pcre': $prettyVersion = preg_replace('{^(\\S+).*}', '$1', PCRE_VERSION); break; case 'uuid': $prettyVersion = phpversion('uuid'); break; case 'xsl': $prettyVersion = LIBXSLT_DOTTED_VERSION; break; default: // None handled extensions have no special cases, skip continue 2; } try { $version = $versionParser->normalize($prettyVersion); } catch (\UnexpectedValueException $e) { continue; } $lib = new CompletePackage('lib-' . $name, $version, $prettyVersion); $lib->setDescription('The ' . $name . ' PHP library'); $this->addPackage($lib); } if (defined('HHVM_VERSION')) { try { $prettyVersion = HHVM_VERSION; $version = $versionParser->normalize($prettyVersion); } catch (\UnexpectedValueException $e) { $prettyVersion = preg_replace('#^([^~+-]+).*$#', '$1', HHVM_VERSION); $version = $versionParser->normalize($prettyVersion); } $hhvm = new CompletePackage('hhvm', $version, $prettyVersion); $hhvm->setDescription('The HHVM Runtime (64bit)'); $this->addPackage($hhvm); } }
/** * @param string $name * @param string $version * @param string $class * * @return PackageInterface */ protected function getPackage($name, $version, $class = 'Composer\\Package\\Package') { static $parser; if (!$parser) { $parser = new VersionParser(); } return new $class($name, $parser->normalize($version), $version); }
public function findPackages($name, $version = null) { if (!$this->hasProviders()) { return parent::findPackages($name, $version); } $name = strtolower($name); if (null !== $version) { $versionParser = new VersionParser(); $version = $versionParser->normalize($version); } $packages = array(); foreach ($this->getProviderNames() as $providerName) { if ($name === $providerName) { $packages = $this->whatProvides(new Pool('dev'), $providerName); foreach ($packages as $package) { if ($name == $package->getName() && (null === $version || $version === $package->getVersion())) { $packages[] = $package; } } } } return $packages; }
protected function initialize() { parent::initialize(); $versionParser = new VersionParser(); try { $prettyVersion = PHP_VERSION; $version = $versionParser->normalize($prettyVersion); } catch (\UnexpectedValueException $e) { $prettyVersion = preg_replace('#^(.+?)(-.+)?$#', '$1', PHP_VERSION); $version = $versionParser->normalize($prettyVersion); } $php = new MemoryPackage('php', $version, $prettyVersion); $php->setDescription('The PHP interpreter'); parent::addPackage($php); $loadedExtensions = get_loaded_extensions(); // Extensions scanning foreach ($loadedExtensions 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); } $ext = new MemoryPackage('ext-' . $name, $version, $prettyVersion); $ext->setDescription('The ' . $name . ' PHP extension'); parent::addPackage($ext); } // 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) { 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 = preg_replace_callback('{^(?:OpenSSL\\s*)?([0-9.]+)([a-z]?).*}', function ($match) { return $match[1] . (empty($match[2]) ? '' : '.' . (ord($match[2]) - 96)); }, OPENSSL_VERSION_TEXT); break; case 'pcre': $prettyVersion = preg_replace('{^(\\S+).*}', '$1', PCRE_VERSION); break; case 'uuid': $prettyVersion = phpversion('uuid'); break; case 'xsl': $prettyVersion = LIBXSLT_DOTTED_VERSION; break; default: // None handled extensions have no special cases, skip continue 2; } try { $version = $versionParser->normalize($prettyVersion); } catch (\UnexpectedValueException $e) { continue; } $lib = new MemoryPackage('lib-' . $name, $version, $prettyVersion); $lib->setDescription('The ' . $name . ' PHP library'); parent::addPackage($lib); } }
/** * @return array */ public function getReleaseTags() { $tags = $this->driver->getTags(); uksort($tags, function ($a, $b) { $aVersion = $a; $bVersion = $b; if ($aVersion === '9999999-dev' || 'dev-' === substr($aVersion, 0, 4)) { $aVersion = 'dev'; } if ($bVersion === '9999999-dev' || 'dev-' === substr($bVersion, 0, 4)) { $bVersion = 'dev'; } $aIsDev = $aVersion === 'dev' || substr($aVersion, -4) === '-dev'; $bIsDev = $bVersion === 'dev' || substr($bVersion, -4) === '-dev'; // push dev versions to the end if ($aIsDev !== $bIsDev) { return $aIsDev ? 1 : -1; } // equal versions are sorted by date if ($aVersion === $bVersion) { return $a->getReleaseDate() > $b->getReleaseDate() ? 1 : -1; } // the rest is sorted by version $res = version_compare($aVersion, $bVersion); if ($res == 1) { return -1; } if ($res == 0) { return 0; } if ($res == -1) { return 1; } return $res; }); $versionParser = new VersionParser(); $normalizedTags = []; foreach ($tags as $version => $id) { try { $normalizedVersion = $versionParser->normalize($version); } catch (\Exception $e) { /* We just continue, repo can have any tags, we just care about valid semver one */ continue; } $tmp = ['version' => $normalizedVersion, 'tag' => $version, 'id' => $id, 'source' => $this->driver->getSource($id)]; $normalizedTags[] = $tmp; } return $normalizedTags; }