Class Version
Version parsing and comparison helper.
-
Core\Object
implements
Core\Chainable
-
Core\Set
implements
Core\Accessor
-
Core\Set\Mutable
implements
Core\Mutator
-
Core\Field
implements
Core\Inquiry
-
Core\Version
implements
Core\Comparable,
Core\Equality
Namespace: Core
Package: Core\Version
Since:
3.0
Requires:
PHP 5.3
Version:
1.0
Located at Version.inc.php
Methods summary
public
|
#
__construct( string $version )
Initialises a new Version instance.
Initialises a new Version instance.
Beside generic version strings, this method also supports parsing of
several SCM keyword strings, e.g. Revision and Id expansions.
Parameters
- $version
Version instance to copy values from or a generic version string to
parse.
Since
3.0
|
public
string
|
#
__toString( )
Returns a normalised version string.
Returns a normalised version string.
A normalized version string contains either a version hierarchy with
an optional revision number or is a standalone revision number.
The hierarchy part contains the major and minor version plus optionally
a release number and an extra version string in the following format:
MajorV.MinorV[.ReleaseNumber][-ExtraString].
Example of a version 1.2.3 with developer release marker and the
revision number 9 is 1.2.3-dev1 (9) .
A standalone revision number uses the alternate revision identifier in
the following form: r.RevisionNumber, e.g. r.9 .
Returns
string Normalised version string.
Since
3.0
Overrides
|
protected
array
|
#
_parseVersion( string $versionString )
Internal version parser.
Parameters
- $versionString
- Version string to parse.
Returns
array Associative array with identified version components extracted from the
source version string. Contains the following entries:
major
Major version number.
minor
Minor version number.
release
Release or patch version number.
extra
Additional version information string, such as alpha , beta or
dev extensions.
revision
Numeric revision number (hashes are not supported).
date
Date of release.
editor
Arbitrary editor information string.
Since
3.0
|
public static
integer
|
#
compare( Core\Version |string $versionA, Core\Version |string $versionB )
Compares two versions. See Core\Version::compareTo() for details on how
versions are compared.
Parameters
- $versionA
A Version instance or a generic version string to compare against the
second argument.
- $versionB
A Version instance or a generic version string to compare against the
first argument.
Returns
integer Returns < 0 if the first version is less than the second; > 0 if the
first version is greater than the second, and 0 if both are equal.
See
Since
3.0
|
public
integer
|
#
compareTo( Core\Version |string $version )
Compares the current version again another version. During comparison,
both versions are normalised and its segments are compared against each
other in the following order; the first difference is reported:
Compares the current version again another version. During comparison,
both versions are normalised and its segments are compared against each
other in the following order; the first difference is reported:
Major, minor and release numbers are compared against each other; any extra version string is scanned for common identifiers and compared accordingly:
unknown_identifier < dev < alpha = a < beta = b < RC = rc < # < pl = p
Any revision number is numerically compared; if no revision number is given, it is considered zero (0);
Any parsed UNIX date stamps are compared against each other.
Extended version comparison as provided by the Version interface is
quite expensive; if possible, scalar version IDs should be used
whenever available.
Parameters
- $version
Another Version instance or a generic version string to compare with
the current version.
Returns
integer Returns < 0 if the current version is less than the argument; > 0 if the
current version is greater than the argument, and 0 if both are equal.
Since
3.0
Implementation of
|
public static
Core\Version
|
#
createWithComponents( integer $major = null, integer $minor = null, integer $release = null, string $extra = null, integer $revision = null, string|integer $date = null, string $editor = null )
Creates a new Version instance from a set of version components.
Creates a new Version instance from a set of version components.
Parameters
- $major
- Major version number.
- $minor
- Minor version number.
- $release
- Release version number.
- $extra
- Extra version information string.
- $revision
- Revision number.
- $date
- Date string or integer UNIX timestamp.
- $editor
- Editor name string.
Returns
Core\Version New Version instance created from the fields provided.
Since
3.1
|
public
string
|
#
hash( )
Returns a hash value based on the stored version data.
Returns a hash value based on the stored version data.
Hash codes of version instances are equal if and only if both instances
are equal according to the specifications of the Core\Version::isEqualTo()
method.
Returns
string Hash value of the object.
See
Since
3.0
Overrides
|
public
boolean
|
#
isEqualTo( Core\Version |string $version )
Tests, whether two versions are equal. Two versions are considered
equal if and only if all version components are equal. This does not
include any editor name stored with the Version instance.
Tests, whether two versions are equal. Two versions are considered
equal if and only if all version components are equal. This does not
include any editor name stored with the Version instance.
Versions are compared based on their version components. A component
is considered equal regardless of its existence; therefore if a version
component is explicitly stated as zero (0) or omitted, both expressions
test equal.
To test whether two versions are equal without doing a binary comparison
on extra information, the Core\Version::compareTo() method should be used
instead:
if (0 == $v1->compareTo($v2)) {
}
Parameters
- $version
Another Version instance or a generic version string to compare with
the current version.
Returns
boolean Returns true , if the provided version and the current Version are
equal, otherwise false .
Since
3.0
Implementation of
|
public
Core\Version
|
#
mergeWith( Core\Version |string $version )
Returns a new combined Version instance of the current and given version.
Version are merged by overwriting all segment in the current version
set with segments of the argument, if a segment of the argument is set.
Returns a new combined Version instance of the current and given version.
Version are merged by overwriting all segment in the current version
set with segments of the argument, if a segment of the argument is set.
Parameters
- $version
- Version instance of version string to merge with current version.
Returns
Core\Version A new Version instance with the merged data of both the current and
argument version.
Since
3.0
|
protected
|
#
versionID( )
Returns the version ID. The returned value is an integer expressing
the version number based purely on the major, minor and release version
components. It is defined by the following expression:
Returns the version ID. The returned value is an integer expressing
the version number based purely on the major, minor and release version
components. It is defined by the following expression:
MajorVersion * 10000 + MinorVersion * 100 + ReleaseNumber
Version data with release number greater than 99 will lead to a corrupt
version ID by modifying minor or even major version segments. Usage of
the version ID should therefore be restricted to controlled version
numbers, e.g. environments with a known version numbering scheme.
Since
3.0
|
__autocreateFactory()
,
__call()
,
__processParameters()
,
attachMethod()
,
chain()
,
getValueForKey()
,
getValueForKeyPath()
,
getValueForUndefinedKey()
,
issetValueForKey()
,
setValueForKey()
,
setValueForKeyPath()
,
setValueForUndefinedKey()
,
uuid()