PHP code example of package-url / packageurl-php

1. Go to this page and download the library: Download package-url/packageurl-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

package-url / packageurl-php example snippets




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);