valorin/debver 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

valorin/debver

最新稳定版本:1.2

Composer 安装命令:

composer require valorin/debver

包简介

Simple PHP helper class for comparing Debian/Ubuntu package version strings.

README 文档

README

Version 1.2 Build Status

Simple PHP helper class for working with Debian/Ubuntu package version strings.

Installing

The easiest way to install Debver is to use Composer, the awesome dependency manager for PHP. Once Composer is installed, run composer.phar require valorin/debver:1.* and composer will do all the hard work for you.

Usage

If you are using the autoloader in Composer (or your framework ties into it), then all you need to do is add a use Debver\Version; statement at the top of each file you wish to use Debver in and us e it like a normal class:

<?php
namespace YourApplication;
use Debver\Version;

$version1 = "5.1.2-1ubuntu3.9";
$version2 = "3.9.4-4ubuntu0.2";

$compare = Version::compare($version1, $version2);

Compare two version strings:

$result = Version::compare($version1, $version2);

if ($result == -1) {
    echo "{$version1} < {$version2}";
} elseif ($result == 0) {
    echo "{$version1} == {$version2}";
} elseif ($result == 1) {
    echo "{$version1} > {$version2}";
}

Extract version string components:

The three components to a version string can be extracted easily: Epoch, Upstream Version, and Debian Revision:

$version = new Version($version1);

$epoch    = $version->getEpoch();
$upstream = $version->getUpstream();
$revision = $version->getRevision();

Ubuntu manual: deb-version

Compare two version strings using dpkg:

If you are running on a Ubuntu/Debian box, you can use dpkg directly to compare two packages (100% accuracy for all of the really wacky version strings). This option was added for testing the custom functions, and I decided to leave it in just in case. Internally it uses dpkg --compare-versions {$version1} lt {$version2} via a system() call.

$result = Version::compareWithDpkg($version1, $version2);

if ($result == -1) {
    echo "{$version1} < {$version2}";
} elseif ($result == 0) {
    echo "{$version1} == {$version2}";
} elseif ($result == 1) {
    echo "{$version1} > {$version2}";
}

Retrieve a "compare string" for storing in a database

Occasionally you need to store a large amount of version numbers in a database and then compare them in bulk using the database itself, rather than extracting the data and manipulating it in code. A "compare string" is a verbose version of the version string that can be compared using basic string comparison functions (> < ==), making it perfect for use in a database..

$string = Version::getCompareString($version);

统计信息

  • 总下载量: 153
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2012-11-01