A parser and builder based on package url spec, implemented in PHP.
License: MIT
composer require package-url/packageurl-php
see also the examples.
<?php
use PackageUrl\PackageUrl;
$purl = (new PackageUrl('composer', 'console'))
->setNamespace('symfony')
->setVersion('6.3.8')
->setQualifiers([
PackageUrl::QUALIFIER_VCS_URL => 'git+https://github.com/symfony/[email protected]',
]);
$purlString = $purl->toString();
// string(96) "pkg:composer/symfony/[email protected]?vcs_url=git%2Bhttps://github.com/symfony/console.git%40v6.3.8"
var_dump($purlString);
// string(96) "pkg:composer/symfony/[email protected]?vcs_url=git%2Bhttps://github.com/symfony/console.git%40v6.3.8"
var_dump((string) $purl);
$purl2 = PackageUrl::fromString($purlString);
// bool(true)
var_dump($purl == $purl2);
Feel free to open pull requests.
See the contribution docs for details.