当前位置: 首页>>代码示例>>PHP>>正文


PHP Version::compare方法代码示例

本文整理汇总了PHP中Version::compare方法的典型用法代码示例。如果您正苦于以下问题:PHP Version::compare方法的具体用法?PHP Version::compare怎么用?PHP Version::compare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Version的用法示例。


在下文中一共展示了Version::compare方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testLessThanCases

 /**
  * @dataProvider provideLessThanCases
  */
 function testLessThanCases($aArray, $bArray)
 {
     $a = $this->makeVersion($aArray);
     $b = $this->makeVersion($bArray);
     $actual = Version::compare($a, $b);
     $this->assertLessThan(0, $actual);
     $actual = Version::compare($b, $a);
     $this->assertGreaterThan(0, $actual);
 }
开发者ID:andrelohmann,项目名称:semver,代码行数:12,代码来源:VersionTest.php

示例2: testCompareVersion

 public function testCompareVersion()
 {
     // test = version
     $version = Version::VERSION;
     $this->assertEquals(0, Version::compare($version));
     // test < version
     $this->assertLessThan(0, Version::compare('0.1'));
     $this->assertLessThan(0, Version::compare($version . '-alfa'));
     $this->assertLessThan(0, Version::compare($version . '-beta'));
     $this->assertLessThan(0, Version::compare($version . '-rc1'));
     // test > version
     $this->assertGreaterThan(0, Version::compare($version . '.1'));
     $this->assertGreaterThan(0, Version::compare($version . '-1'));
 }
开发者ID:nidzix,项目名称:Newscoop,代码行数:14,代码来源:VersionTest.php

示例3: Version

<?php

require 'Version.class.php';
$version = '2.7.1';
$obj = new Version();
// 版本转数字
$version_code = $obj->version_to_integer($version);
echo $version_code . '<br>';
// 20701
// 数字转版本
$version = $obj->integer_to_version($version_code);
echo $version . '<br>';
// 2.7.1
// 检查版本
$version = '1.1.a';
var_dump($obj->check($version));
// false
// 比较两个版本
$version1 = '2.9.9';
$version2 = '10.0.1';
$result = $obj->compare($version1, $version2);
echo $result;
// -1
开发者ID:xfdipzone,项目名称:27.Version,代码行数:23,代码来源:demo.php

示例4: foreach

 /**
  * Choose a Package from the collection which satisfies the
  * specified selection filters. If no suitable package can
  * be found the special NullPackage is returned.
  *
  * @param platformId  (Integer) PlatformId filter.
  * @param title  (String) Symbolic name of the package to download. Default="Doomsday".
  * @param unstable  (Boolean) @c true= Only consider 'unstable' packs.
  * @param hasDownload  (Boolean) @c true= Only consider 'downloadable' packs.
  * @return  (Object) Chosen package.
  */
 private function &choosePackage($platformId = PID_ANY, $title = "Doomsday", $unstable = FALSE, $downloadable = TRUE)
 {
     $unstable = (bool) $unstable;
     $downloadable = (bool) $downloadable;
     if (isset($this->packages)) {
         $matchTitle = (bool) (strlen($title) > 0);
         $found = 0;
         foreach ($this->packages as &$pack) {
             if ($pack->platformId() !== $platformId) {
                 continue;
             }
             if ($matchTitle && strcasecmp($pack->title(), $title)) {
                 continue;
             }
             if ($unstable != $pack instanceof AbstractUnstablePackage) {
                 continue;
             }
             if ($downloadable != ($pack instanceof iDownloadable && ($pack->hasDirectDownloadUri() || $pack->hasDirectDownloadFallbackUri()))) {
                 continue;
             }
             // Found something suitable.
             if (!$found || Version::compare($pack->version(), $found->version()) > 0) {
                 $found = $pack;
             }
         }
         if ($found) {
             return $found;
         }
     }
     // Nothing suitable.
     return self::$nullPack;
 }
开发者ID:laszloekovacs,项目名称:Doomsday-Engine,代码行数:43,代码来源:buildrepository.php

示例5: compareVersionWithCompare

 private static function compareVersionWithCompare(Version $aFrom = null, Version $aTo = null, $sFromCompare, $sToCompare)
 {
     if (self::isSameDirection($sFromCompare, $sToCompare)) {
         return self::INTERSECT;
     } else {
         if (null !== $aFrom and null !== $aTo) {
             $compare = $aFrom->compare($aTo);
             if ($compare > 0) {
                 if ('<' === $sFromCompare or '<=' === $sFromCompare) {
                     return self::INTERSECT;
                 } else {
                     return self::SEPARATE;
                 }
             } else {
                 if ($compare < 0) {
                     if ('<' === $sFromCompare or '<=' === $sFromCompare) {
                         return self::SEPARATE;
                     } else {
                         return self::INTERSECT;
                     }
                 } else {
                     if (0 === $compare) {
                         if (('<=' === $sFromCompare or '>=' === $sFromCompare) and ('<=' === $sToCompare or '>=' === $sToCompare)) {
                             return self::INTERSECT;
                         } else {
                             return self::SEPARATE;
                         }
                     } else {
                         throw new VersionException('compare error : `%s`', $compare);
                     }
                 }
             }
         } else {
             return self::INTERSECT;
         }
     }
 }
开发者ID:JeCat,项目名称:framework,代码行数:37,代码来源:VersionScope.php


注:本文中的Version::compare方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。