semantic versioning.php
1.1.0
시맨틱 버전 2.0과 호환되는 시맨틱 버전을 구문 분석하고 비교하기위한 작은 독립 라이브러리.
작곡가를 다운로드하고 rayne/semantic-versioning 설치하십시오.
composer require rayne/semantic-versioning
저장소를 복제하십시오
git clone https://github.com/rayne/semantic-versioning.php.git
개발 종속성을 설치하십시오
composer install --dev
테스트를 실행하십시오
./vendor/bin/phpunit
라이브러리에는 다음 수업이 포함되어 있습니다.
InvalidVersionException : 유효하지 않은 입력에 대한 SemanticVersion 에 의해 던져졌습니다
SemanticComparator : SemanticVersion Objects 비교를위한 Semantic 버전 관리 비교기
SemanticVersion : 유효하지 않은 버전에서 RuntimeException 던지는 Semantic Versionsing Parser
예제는 테스트 스위트의 일부입니다. 자세한 내용은 tests 디렉토리를 살펴보십시오.
use Rayne SemanticVersioning SemanticVersion ;
$ version = new SemanticVersion ( ' 1.0.0-beta+exp.sha.5114f85 ' );
assert ( ' 1.0.0-beta+exp.sha.5114f85 ' === ( string ) $ version );
assert ( 1 === $ version -> getMajor ());
assert ( 0 === $ version -> getMinor ());
assert ( 0 === $ version -> getPatch ());
assert ( ' beta ' === $ version -> getPre ());
assert ( ' exp.sha.5114f85 ' === $ version -> getMeta ());
assert ( ' 1.0.0-beta+exp.sha.5114f85 ' === $ version -> getVersion ());
assert ( true === $ version -> isMajorRelease ());
assert ( false === $ version -> isMinorRelease ());
assert ( false === $ version -> isPatchRelease ());
assert ( true === $ version -> isPreRelease ()); use Rayne SemanticVersioning SemanticComparator ;
use Rayne SemanticVersioning SemanticVersion ;
$ comparator = new SemanticComparator ;
$ alpha = new SemanticVersion ( ' 1.0.0-alpha ' );
$ candidate = new SemanticVersion ( ' 1.0.0-rc.1 ' );
$ candidate_meta = new SemanticVersion ( ' 1.0.0-rc.1+ci ' );
$ release = new SemanticVersion ( ' 1.0.0 ' );
// $alpha < $candidate
assert ( $ comparator ( $ alpha , $ candidate ) < 0 );
assert ( $ comparator -> compare ( $ alpha , $ candidate ) < 0 );
// $candidate == $candidate_meta
assert ( $ comparator ( $ candidate , $ candidate_meta ) == 0 );
assert ( $ comparator -> compare ( $ candidate , $ candidate_meta ) == 0 );
// $release > $candidate
assert ( $ comparator ( $ release , $ candidate ) > 0 );
assert ( $ comparator -> compare ( $ release , $ candidate ) > 0 ); use Rayne SemanticVersioning SemanticComparator ;
use Rayne SemanticVersioning SemanticVersion ;
$ versions = [
$ candidate = new SemanticVersion ( ' 1.0.0-rc.1 ' ),
$ release = new SemanticVersion ( ' 1.0.0 ' ),
$ alpha = new SemanticVersion ( ' 1.0.0-alpha ' ),
];
// Sort by semantic precedence.
usort ( $ versions , new SemanticComparator );
assert ( $ versions [ 0 ] === $ alpha );
assert ( $ versions [ 1 ] === $ candidate );
assert ( $ versions [ 2 ] === $ release );