Skip to content

Commit

Permalink
upgrade examples
Browse files Browse the repository at this point in the history
  • Loading branch information
llaville committed Aug 1, 2024
1 parent f208718 commit 336e44a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
Table Of Contents :

1. A `phar-manifest.php` script that demonstrate how to use programmatically the API to generate manifests in different format.
1. A basic `app-fixtures` application that will be support of a tutorial.
2. A basic `app-fixtures` application that will be support of a tutorial.
39 changes: 27 additions & 12 deletions examples/phar-manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ public function log($level, string|Stringable $message, array $context = []): vo
}
};

if (count($argv) < 2) {
// Print Usage.
$logger->log('notice', 'If you want to build a manifest in specific format, please use one of these syntaxes');
$logger->log('notice', sprintf('Usage: php %s %s :: %s', __FILE__, 'sbom', 'SBOM XML format'));
$logger->log('notice', sprintf('Usage: php %s %s :: %s', __FILE__, 'plain', 'Plain text (key: value) format'));
$logger->log('notice', sprintf('Usage: php %s %s :: %s', __FILE__, 'ansi', 'Console Line format'));
$logger->log('notice', sprintf('Usage: php %s %s :: %s', __FILE__, 'console', 'Console Table format'));
exit(1);
}

(new PhpSettingsHandler($logger))->check();

$configLoader = new ConfigurationLoader();
Expand All @@ -43,26 +53,31 @@ public function log($level, string|Stringable $message, array $context = []): vo
$factory = new ManifestFactory($config, true, (new BoxHelper())->getBoxVersion(), (new Application())->getVersion());

try {
// 1.
$format = 'xml'; // Allowed values are: xml, json
$specVersion = '1.4'; // Allowed values are: 1.1, 1.2, 1.3, 1.4
$result = $factory->toSbom($format, $specVersion);

// 2.
//$result = $factory->toText();

// 3.
//$result = $factory->toHighlight();
if ($argv[1] == 'sbom') {
// 1.
$format = 'xml'; // Allowed values are: xml, json
$specVersion = '1.4'; // Allowed values are: 1.1, 1.2, 1.3, 1.4, 1.5, 1.6
$result = $factory->toSbom($format, $specVersion);
} elseif ($argv[1] == 'plain') {
// 2.
$result = $factory->toText();
} elseif ($argv[1] == 'ansi') {
// 3.
$result = $factory->toHighlight();
} elseif ($argv[1] == 'console') {
// 4.
$result = $factory->toConsole();
}
} catch (Throwable $e) {
echo $e->getMessage(), PHP_EOL;
} finally {
$logger->log(
'info',
'Using composer.json : ' . $config->getComposerJson()
'Using composer.json : ' . $config->getComposerJson()?->path
);
$logger->log(
'info',
'Using composer.lock : ' . $config->getComposerLock()
'Using composer.lock : ' . $config->getComposerLock()?->path
);
echo $result, PHP_EOL;
}

0 comments on commit 336e44a

Please sign in to comment.