phar-io/version's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
The "phar-io/version" is a useful PHP library that allows users to handle version information and constraints within their applications. It gives developers the ability to describe both a range of versions or a single, discrete version number, following the widely-accepted Semantic Versioning schema. It also supports typical mathematic operators for easy range descriptions and two special operators, caret (^) and tilde (~), for additional versioning flexibility. In addition to version handling and constraint management, pre-release label support is featured, enhancing version comparisons further.
Utilizing "phar-io/version" within your PHP projects involves integrating it with your project using Composer, and subsequently executing commands in your PHP code depending on your needs. For instance, to add the "phar-io/version" as a local, per-project dependency, one would typically run the
composer require phar-io/version in their project directory.
Once installed, you can use it as shown in the examples below:
use PharIo\Version\Version; use PharIo\Version\VersionConstraintParser; $parser = new VersionConstraintParser(); $caret_constraint = $parser->parse( '^7.0' ); $tilde_constraint = $parser->parse( '~1.1.0' );
Here, a new instance of the
VersionConstraintParser is being created and used to parse various version strings. To verify whether certain versions comply with these parsed constraints, you could code:
$caret_constraint->complies( new Version( '7.0.17' ) ); // returns true $tilde_constraint->complies( new Version( '1.1.4' ) ); // returns true
Furthermore, version comparisons, considering pre-release labels, can be achieved as in the following snippet:
$leftVersion = new PharIo\Version\Version('3.0.0-alpha.1'); $rightVersion = new PharIo\Version\Version('3.0.0-alpha.2'); $leftVersion->isGreaterThan($rightVersion); // returns false $rightVersion->isGreaterThan($leftVersion); // returns true
These examples show ways in which you can integrate the use of "phar-io/version" into your projects to manage and manipulate version information effectively.
The documentation for the "phar-io/version" can be found directly within its GitHub repository. The GitHub README file for the repository includes detailed instructions on installation and usage, along with code examples that comprehensively demonstrate functionality. This resource serves as a comprehensive guide for understanding and leveraging the powerful features provided by "phar-io/version" in your PHP projects.