2017 © Pedro Peláez
 

library version

Value Object that represents a SemVer-compliant version number.

image

nikolaposa/version

Value Object that represents a SemVer-compliant version number.

  • Thursday, June 14, 2018
  • by nikolaposa
  • Repository
  • 4 Watchers
  • 52 Stars
  • 27,617 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 7 Forks
  • 0 Open issues
  • 23 Versions
  • 55 % Grown

The README.md

Version

Build Scrutinizer Code Quality Code Coverage Latest Stable Version PDS Skeleton, (*1)

Value Object that represents a SemVer-compliant version number., (*2)

Installation

The preferred method of installation is via Composer. Run the following command to install the latest version of a package and add it to your project's composer.json:, (*3)

composer require nikolaposa/version

Usage

Creating a Version object via named constructor and accessing its values

use Version\Extension\Build;
use Version\Extension\PreRelease;
use Version\Version;

$v = Version::from(2, 0, 0, PreRelease::from('alpha', '1'), Build::from('20191222232137'));

echo $v->getMajor(); //2
echo $v->getMinor(); //0
echo $v->getPatch(); //0
print_r($v->getPreRelease()->getIdentifiers()); //Array([0] => alpha [1] => 1)
echo $v->getPreRelease()->toString(); //alpha.1
print_r($v->getBuild()->getIdentifiers()); //Array([0] => 20191222232137)
echo $v->getBuild()->toString(); //20191222232137

Creating a Version object from a string

$v = Version::fromString('1.10.0');

echo $v->toString(); //1.10.0

Comparing Version objects

$v1 = Version::fromString('1.10.0');
$v2 = Version::fromString('2.3.3');

var_dump($v1->isLessThan($v2)); //bool(true)
var_dump($v1->isGreaterThan($v2)); //bool(false)
var_dump($v1->isEqualTo($v2)); //bool(false)

var_dump($v2->isLessThan($v1)); //bool(false)
var_dump($v2->isGreaterThan($v1)); //bool(true)

Matching Version objects against constraints

$v = Version::fromString('2.2.0');

var_dump($v->matches(OperationConstraint::equalTo(Version::fromString('2.2.0')))); //bool(true)
var_dump($v->matches(OperationConstraint::notEqualTo(Version::fromString('2.2.0')))); //bool(true)
var_dump($v->matches(OperationConstraint::fromString('>=2.0.0 <2.3.0'))); //bool(true)
var_dump($v->matches(OperationConstraint::fromString('>=2.0.0 <2.1.0 || 2.2.0'))); //bool(true)

Version operations

$v = Version::fromString('1.10.0');

$v1101 = $v->incrementPatch();
echo $v1101->toString(); //1.10.1

$v1110 = $v1101->incrementMinor();
echo $v1110->toString(); //1.11.0

$v2 = $v1101->incrementMajor();
echo $v2->toString(); //2.0.0

$v2Alpha = $v2->withPreRelease('alpha');
echo $v2Alpha->toString(); //2.0.0-alpha

$v2Alpha111 = $v2Alpha->withBuild('111');
echo $v2Alpha111->toString(); //2.0.0-alpha+111

Version Collection

$versions = new VersionCollection(
    Version::from(1, 0, 1),
    Version::fromString('1.1.0'),
    Version::fromString('2.3.3')
);

echo count($versions); //3

$versions = $versions->sortedDescending();

//Outputs: 2.3.3, 1.1.0, 1.0.1
foreach ($versions as $version) {
    echo $version->toString();
}

$minorReleases = $versions->minorReleases();
echo $minorReleases->first(); //1.1.0

Credits

License

Released under MIT License - see the License File for details., (*4)

The Versions

14/06 2018

dev-master

9999999-dev https://github.com/nikolaposa/version

Value Object that represents a SemVer-compliant version number.

  Sources   Download

MIT

The Requires

  • php ^7.2.0

 

The Development Requires

version semantic versioning semver

14/06 2018

3.1.0

3.1.0.0 https://github.com/nikolaposa/version

Value Object that represents a SemVer-compliant version number.

  Sources   Download

MIT

The Requires

  • php ^7.2.0

 

The Development Requires

version semantic versioning semver

28/05 2018

3.0.x-dev

3.0.9999999.9999999-dev https://github.com/nikolaposa/version

Value Object that represents a SemVer-compliant version number.

  Sources   Download

MIT

The Requires

  • php ^7.1.0

 

The Development Requires

version semantic versioning semver

28/05 2018

3.0.2

3.0.2.0 https://github.com/nikolaposa/version

Value Object that represents a SemVer-compliant version number.

  Sources   Download

MIT

The Requires

  • php ^7.1.0

 

The Development Requires

version semantic versioning semver

27/05 2018

dev-improvement/versions-collection-greater-usability

dev-improvement/versions-collection-greater-usability https://github.com/nikolaposa/version

Value Object that represents a SemVer-compliant version number.

  Sources   Download

MIT

The Requires

  • php ^7.2.0

 

The Development Requires

version semantic versioning semver

05/05 2018

3.0.1

3.0.1.0 https://github.com/nikolaposa/version

Value Object that represents a SemVer-compliant version number.

  Sources   Download

MIT

The Requires

  • php ^7.2.0

 

The Development Requires

version semantic versioning semver

05/05 2018

dev-improvement/align-with-composer-version-parsing

dev-improvement/align-with-composer-version-parsing https://github.com/nikolaposa/version

Value Object that represents a SemVer-compliant version number.

  Sources   Download

MIT

The Requires

  • php ^7.2.0

 

The Development Requires

version semantic versioning semver

02/05 2018

3.0.0

3.0.0.0 https://github.com/nikolaposa/version

Value Object that represents a SemVer-compliant version number.

  Sources   Download

MIT

The Requires

  • php ^7.2.0

 

The Development Requires

version semantic versioning semver

22/04 2018

2.2.2

2.2.2.0 https://github.com/nikolaposa/version

Value Object that represents a SemVer-compliant version number.

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

version semantic versioning semver

22/04 2018

2.2.x-dev

2.2.9999999.9999999-dev https://github.com/nikolaposa/version

Value Object that represents a SemVer-compliant version number.

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

version semantic versioning semver

01/01 2017

2.2.1

2.2.1.0 https://github.com/nikolaposa/version

Value Object representing a version number that is in compliance with the SemVer specification.

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

version semantic versioning semver

14/07 2016

2.2.0

2.2.0.0 https://github.com/nikolaposa/version

Value Object representing a version number that is in compliance with the SemVer specification.

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

version semantic versioning semver

11/06 2016

2.1.0

2.1.0.0 https://github.com/nikolaposa/version

Value Object representing a version number that is in compliance with the SemVer specification.

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

version semantic versioning semver

02/06 2016

2.0.1

2.0.1.0 https://github.com/nikolaposa/version

Value Object representing a version number that is in compliance with the SemVer specification.

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

version semantic versioning semver

02/06 2016

2.0.0

2.0.0.0 https://github.com/nikolaposa/version

Value Object representing a version number that is in compliance with the SemVer specification.

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

version semantic versioning semver

09/04 2016

1.2.x-dev

1.2.9999999.9999999-dev https://github.com/nikolaposa/version

Value Object representing a version number that is in compliance with the SemVer specification.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

version semantic versioning

09/04 2016

1.2.3

1.2.3.0 https://github.com/nikolaposa/version

Value Object representing a version number that is in compliance with the SemVer specification.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

version semantic versioning

09/04 2016

1.2.2

1.2.2.0 https://github.com/nikolaposa/version

Value Object representing a version number that is in compliance with the SemVer specification.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

version semantic versioning

27/09 2015

1.2.1

1.2.1.0 https://github.com/nikolaposa/version

Value Object representing a version number that is in compliance with the SemVer specification.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

version semantic versioning

27/09 2015

1.2.0

1.2.0.0 https://github.com/nikolaposa/version

Value Object representing a version number that is in compliance with the SemVer specification.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

version semantic versioning

26/09 2015

1.1.0

1.1.0.0 https://github.com/nikolaposa/version

Value Object representing a version number that is in compliance with the SemVer specification.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

version semantic versioning

20/09 2015

1.0.0

1.0.0.0 https://github.com/nikolaposa/version

Value Object representing a version number that is in compliance with the SemVer specification.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

version semantic versioning

19/09 2015

1.0.0-alpha

1.0.0.0-alpha https://github.com/nikolaposa/version

Value Object representing a version number that is in compliance with the SemVer specification.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

version semantic versioning