본문 바로가기
← 패키지 목록

Semver

인증된 제출자

composer/semver

제출자 이우진
최신 v3.5.0라이센스 MIT배포 2026년 10월 4일
DevOps

버전 비교 유틸리티와 버전 제약 조건의 파싱·검증 기능을 제공하는 라이브러리입니다.

composer/semver

버전 비교 유틸리티와 버전 제약 조건의 파싱·검증 기능을 제공하는 라이브러리입니다.

가능한 한 semver(유의적 버전)를 따르지만, version_compare 및 하위 호환성의 제약 때문에 semver를 엄격하게 구현하지는 못합니다.

원래 composer/composer의 일부로 작성되었으며, 현재는 별도의 라이브러리로 분리되어 있습니다.

Continuous Integration PHP Lint PHPStan

설치

다음 명령으로 최신 버전을 설치합니다.

composer require composer/semver

요구 사항

  • PHP 5.3.2가 필요하며, 최신 PHP 버전 사용을 적극 권장합니다.

버전 비교

버전 비교 방식에 관한 자세한 내용은 getcomposer.org의 버전 문서를 참고하세요.

기본 사용법

검증과 정규화

Composer\Semver\VersionParser 클래스는 버전과 제약 조건의 파싱·정규화·검증을 위한 다음 메서드를 제공합니다.

숫자로 된 버전은 내부 일관성과 version_compare 호환성을 위해 네 부분으로 정규화됩니다. 예를 들어 1.2.3은 1.2.3.0이 됩니다. 정규화된 버전은 내부 제약 조건 처리에 사용하며 최종 사용자에게 표시해서는 안 됩니다.

버전 처리:

  • isValid($version)
  • normalize($version, $fullVersion = null)
  • normalizeBranch($name)
  • normalizeDefaultBranch($name)

제약 조건 처리:

  • parseConstraints($constraints)

안정성 처리:

  • parseStability($version)
  • normalizeStability($stability)

비교

Composer\Semver\Comparator 클래스는 버전 비교를 위한 다음 메서드를 제공합니다.

  • greaterThan($v1, $v2)
  • greaterThanOrEqualTo($v1, $v2)
  • lessThan($v1, $v2)
  • lessThanOrEqualTo($v1, $v2)
  • equalTo($v1, $v2)
  • notEqualTo($v1, $v2)

각 함수는 버전 문자열 두 개를 인수로 받아 불리언 값을 반환합니다.

use Composer\Semver\Comparator; Comparator::greaterThan('1.25.0', '1.24.0'); // 1.25.0 > 1.24.0

Semver

Composer\Semver\Semver 클래스는 다음 메서드를 제공합니다.

  • satisfies($version, $constraints)
  • satisfiedBy(array $versions, $constraint)
  • sort($versions)
  • rsort($versions)

버전 구간

Composer\Semver\Intervals 정적 클래스는 복잡한 제약 조건을 처리하거나 제약 조건에서 버전 구간을 읽는 유틸리티를 제공합니다.

use Composer\Semver\Intervals; // Checks whether $candidate is a subset of $constraint Intervals::isSubsetOf(ConstraintInterface $candidate, ConstraintInterface $constraint); // Checks whether $a and $b have any intersection, equivalent to $a->matches($b) Intervals::haveIntersections(ConstraintInterface $a, ConstraintInterface $b); // Optimizes a complex multi constraint by merging all intervals down to the smallest // possible multi constraint. The drawbacks are this is not very fast, and the resulting // multi constraint will have no human readable prettyConstraint configured on it Intervals::compactConstraint(ConstraintInterface $constraint); // Creates an array of numeric intervals and branch constraints representing a given constraint Intervals::get(ConstraintInterface $constraint); // Clears the memoization cache when you are done processing constraints Intervals::clear()

자세한 내용은 클래스의 문서 주석을 참고하세요.

라이선스

composer/semver는 MIT 라이선스로 배포됩니다. 자세한 내용은 LICENSE 파일을 참고하세요.