本文整理匯總了PHP中Composer\Package\Version\VersionParser::normalize方法的典型用法代碼示例。如果您正苦於以下問題:PHP VersionParser::normalize方法的具體用法?PHP VersionParser::normalize怎麽用?PHP VersionParser::normalize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Composer\Package\Version\VersionParser
的用法示例。
在下文中一共展示了VersionParser::normalize方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: checkPhpVersion
/**
* 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,
],
];
}
示例2: initialize
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);
}
}
示例3: prepare
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'];
}
示例4: testMemoryPackageHasExpectedMarshallingSemantics
/**
* 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);
}
示例5: validatePackage
/**
* @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;
}
示例6: getMinimalPackages
/**
* {@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;
}
示例7: isVersionMatching
/**
* 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);
}
示例8: updateVersion
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;
}
示例9: skip
/**
* 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;
}
}
示例10: getNormalizedCurrentPhpVersion
/**
* 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;
}
示例11: findPackage
/**
* {@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;
}
}
}
示例12: createComposerInMemoryPackage
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;
}
示例13: testWhatProvides
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());
}
示例14: findPackages
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;
}
示例15: testFindRecommendedRequireVersion
/**
* @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);
}