PHP code example of sbominator / sbom-lib

1. Go to this page and download the library: Download sbominator/sbom-lib 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/ */

    

sbominator / sbom-lib example snippets



$generator = new SpdxSBOMGenerator($dependencies);
$SBOMstring = $generator->generate();


use SBOMinator\Lib\Scanner\FileScanner;

/*
 * You can pass the maximum depth of the subdirectories to scan (default is 10)
 * and an array of file extensions to scan for. (If you want to work with all available parsers, you can use the default ['json', 'lock'])
 */ 

$fileScanner = new FileScanner(10, ['json', 'lock']);

$dependencies = $fileScanner->scanForDependencies(getcwd());

use SBOMinator\Parser\ComposerParser;

$parser = new ComposerParser();

// You can omit dev packages if you want by calling withoutDevPackages() on the parser.
$parser = (new ComposerParser())->withoutDevPackages();

$parser->loadFromFile('composer.lock');

$parser->loadFromString(file_get_contents('composer.lock'));

$dependencyTree = $parser->parseDependencies();