• Stars
    star
    169
  • Rank 223,796 (Top 5 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 8 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Semantic versioning helper library for PHP

SemVer

SemVer

Semantic versioning helper library β€’ Created by Chris Kankiewicz (@PHLAK)

Join our Community Become a Sponsor One-time Donation
Latest Stable Version Total Downloads License GitHub branch checks state


Requirements

Installation

composer require phlak/semver

Initializing

use PHLAK\SemVer;

$version = new SemVer\Version(); // Initilializes to '0.1.0'

Or initialize with a custom version by passing a version string on creation. Accepts any valid semantic version string with or without a preceding v.

$version = new SemVer\Version('v1.2.3-alpha.5+sha.8d31ff4');

Or parse an incomple version string with the static Version::parse() constructor.

$version = SemVer\Version::parse('v1') // Initializes to '1.0.0'
$version = SemVer\Version::parse('v1.2') // Initializes to '1.2.0'

Usage

Retrieve the version or individual values

$version = new SemVer\Version('v1.2.3-beta.4+007');

echo $version;             // '1.2.3-beta.4+007'
echo $version->major;      // 1
echo $version->minor;      // 2
echo $version->patch;      // 3
echo $version->preRelease; // 'beta.4'
echo $version->build;      // '007'

Increment the version

$version = new SemVer\Version('v1.2.3');

$version->incrementMajor();      // v1.2.3 -> v2.0.0
$version->incrementMinor();      // v1.2.3 -> v1.3.0
$version->incrementPatch();      // v1.2.3 -> v1.2.4
$version->incrementPreRelease(); // v1.2.3-alpha.5 -> v1.2.3-alpha.6

Set (override) the version or individual values

$version = new SemVer\Version();

$version->setVersion('v1.2.3');  // v1.2.3
$version->setMajor(3);           // v1.2.3 -> v3.0.0
$version->setMinor(5);           // v1.2.3 -> v1.5.0
$version->setPatch(7);           // v1.2.3 -> 1.2.7
$version->setPreRelease('rc.2'); // v1.2.3 -> v1.2.3-rc.2
$version->setBuild('007');       // v1.2.3 -> v1.2.3+007

Clear pre-release / build values

$version->setPreRelease(null); // v1.2.3-rc.2 -> v1.2.3
$version->setBuild(null);      // v1.2.3+007 -> v1.2.3

Compare two SemVer objects

$version1 = new SemVer('v1.2.3');
$version2 = new SemVer('v3.2.1');

$version1->gt($version2);  // false
$version1->lt($version2);  // true
$version1->eq($version2);  // false
$version1->neq($version2); // true
$version1->gte($version2); // false
$version1->lte($version2); // true

Troubleshooting

For general help and support join our GitHub Discussions or reach out on Twitter.

Please report bugs to the GitHub Issue Tracker.

Copyright

This project is liscensed under the MIT License.

More Repositories

1

Twine

String manipulation, leveled up!
PHP
496
star
2

Splat

Glob-like file and pattern matching utility.
PHP
106
star
3

docker-mumble

Docker image for Mumble server.
Dockerfile
87
star
4

Uses

The hardware and software I use on a regular basis.
60
star
5

Config

PHP library for simple configuration management
PHP
49
star
6

Soxy

Bash script for starting and stopping a SOCKS proxy tunnel over SSH in Linux.
Shell
26
star
7

StrGen

PHP library for simple, secure random string generation (e.g. - passwords / salts).
PHP
19
star
8

presentation

Presentation template using reveal.js + Tailwind CSS
HTML
11
star
9

Colorizer

PHP library for generating persistantly unique colors from a string.
PHP
11
star
10

docker-openvpn

Docker image for OpenVPN client/server.
Dockerfile
11
star
11

laravelcollective-html-form-snippets

Sublime Text 3 snippets for LaravelCollective/html form elements.
10
star
12

docker-minecraft

Docker image for (vanilla) Minecraft server.
Dockerfile
9
star
13

lifx-client

PHP client library for the LIFX API (v1)
PHP
8
star
14

vueColorClock

The color changing clock.
HTML
8
star
15

jColorClock

A color changing clock written in JavaScript.
JavaScript
6
star
16

Chronometer

Measure the passing of time.
PHP
6
star
17

Stash

Simple PHP caching library
PHP
6
star
18

CloudDrop

Store and retrieve files in cloud storage providers (i.e. Dropbox, Google Drive, Microsoft OneDrive, Amazon Cloud Drive, etc.)
PHP
5
star
19

sublime-text

My Sublime Text configuration.
Python
5
star
20

docker-speedtest

Docker image for the Speedtest CLI
Dockerfile
5
star
21

laravelcollective-html-form-snippets-atom

Atom snippets for LaravelCollective HTML form elements.
4
star
22

docker-syncthing

Docker image for Syncthing client/node.
Dockerfile
4
star
23

SemVer-CLI

Command line tool for managing semantic versioning within a project.
PHP
4
star
24

Resume.php

[DEPRECATED] My resume as a PHP class.
PHP
4
star
25

chriskankiewicz.com

My internet homepage.
PHP
3
star
26

docker-soxy

Docker image for SOCKS proxy client.
Dockerfile
3
star
27

github-backup

Shell + Python script for backing up GitHub repositories to local git bundles.
Shell
3
star
28

dont-fear-the-regex

Crash course presentation on regular expressions.
HTML
3
star
29

docker-flexget

Docker image for Flexget client.
Dockerfile
3
star
30

docker-hangoutsbot

Docker image for Hangoutsbot client.
Dockerfile
3
star
31

Cafelias

Randomly generated coffee slugs
PHP
2
star
32

docker-valheim

Docker image for Valheim dedicated server.
Dockerfile
2
star
33

restic-init

Initialization script for the restic backup program.
Shell
2
star
34

dotfiles

My custom configuration files for Linux.
Shell
2
star
35

docker-youtube-dl

Docker image for youtube-dl
Dockerfile
2
star
36

docker-transmission

Docker image for Transmission Daemon.
Dockerfile
2
star
37

string-manipulation-leveled-up

String manipulation, leveled up! Twine presentation slides.
JavaScript
2
star
38

CodingStandards

A pre-defined set of coding standards for PHP CS Fixer.
PHP
2
star
39

adguard-home-compose

A docker-compose configuration for Adguard Home
Shell
2
star
40

inner-circle-bot

The Inner Circle chat bot.
PHP
2
star
41

docker-iperf

Docker image for iperf server.
Dockerfile
2
star
42

Collection

Lightweight collection library
PHP
2
star
43

xhtml-transitional-template

A basic XHTML compliant web page template.
JavaScript
2
star
44

blog.chriskankiewicz.com

Pelican repository for http://blog.chriskankiewicz.com
HTML
1
star
45

dev-tools

An opiniated set of development packages and tools.
PHP
1
star
46

linux-machine-id

Get the unique machine ID on Linux.
Shell
1
star
47

webauth_redirect

Drupal module for redirecting anonymous users trying to access /user or /admin to an ASU webauth login page.
PHP
1
star
48

discord-bot

PHP
1
star
49

syncthing-compose

A docker-compose configuration for Syncthing.
Makefile
1
star
50

docker-crashplan

Docker image for CrashPlan client.
Shell
1
star
51

twine-docs

Twine Documentation
Blade
1
star
52

ubuntu-setup.sh

[DEPRECATED] Interactive script to automate Ubuntu setup after installation.
Shell
1
star
53

phlak.net

Official PHLAK.NET homepage.
JavaScript
1
star
54

link-shortener

Custom link shortener app
PHP
1
star
55

PyBlackjack

Personal project to learn some Python, allows you to play Blackjack.
Python
1
star
56

docker-ssh-tunnel

Docker image for SSH tunnel.
Dockerfile
1
star