12
12
exit (1 );
13
13
}
14
14
15
- $ dependencies = dependencies ();
15
+ $ package = package ();
16
16
$ version = version ();
17
+ $ dependencies = dependencies ();
17
18
18
- manifest ($ argv [1 ], $ version , $ dependencies );
19
- sbom ($ argv [2 ], $ version , $ dependencies );
19
+ manifest ($ argv [1 ], $ package , $ version , $ dependencies );
20
+ sbom ($ argv [2 ], $ package , $ version , $ dependencies );
20
21
21
- function manifest (string $ outputFilename , string $ version , array $ dependencies ): void
22
+ function manifest (string $ outputFilename , array $ package , string $ version , array $ dependencies ): void
22
23
{
23
- $ buffer = 'phpunit/phpunit: ' . $ version . "\n" ;
24
+ $ buffer = sprintf (
25
+ '%s/%s: %s ' . "\n" ,
26
+ $ package ['group ' ],
27
+ $ package ['name ' ],
28
+ $ version
29
+ );
24
30
25
31
foreach ($ dependencies as $ dependency ) {
26
32
$ buffer .= $ dependency ['name ' ] . ': ' . $ dependency ['version ' ];
@@ -35,7 +41,7 @@ function manifest(string $outputFilename, string $version, array $dependencies):
35
41
file_put_contents ($ outputFilename , $ buffer );
36
42
}
37
43
38
- function sbom (string $ outputFilename , string $ version , array $ dependencies ): void
44
+ function sbom (string $ outputFilename , array $ package , string $ version , array $ dependencies ): void
39
45
{
40
46
$ writer = new XMLWriter ;
41
47
@@ -50,11 +56,11 @@ function sbom(string $outputFilename, string $version, array $dependencies): voi
50
56
51
57
writeComponent (
52
58
$ writer ,
53
- ' phpunit ' ,
54
- ' phpunit ' ,
59
+ $ package [ ' group ' ] ,
60
+ $ package [ ' name ' ] ,
55
61
$ version ,
56
- ' The PHP Unit Testing framework ' ,
57
- [ ' BSD-3-Clause ' ]
62
+ $ package [ ' description ' ] ,
63
+ $ package [ ' license ' ]
58
64
);
59
65
60
66
foreach ($ dependencies as $ dependency ) {
@@ -92,6 +98,26 @@ function dependencies(): array
92
98
)['packages ' ];
93
99
}
94
100
101
+ function package (): array
102
+ {
103
+ $ data = json_decode (
104
+ file_get_contents (
105
+ __DIR__ . '/../../composer.json '
106
+ ),
107
+ true
108
+ );
109
+
110
+ [$ group , $ name ] = explode ('/ ' , $ data ['name ' ]);
111
+
112
+ return [
113
+ 'group ' => $ group ,
114
+ 'name ' => $ name ,
115
+ 'description ' => $ data ['description ' ],
116
+ 'license ' => [$ data ['license ' ]],
117
+ 'branch ' => $ data ['extra ' ]['branch-alias ' ]['dev-master ' ]
118
+ ];
119
+ }
120
+
95
121
function version (): string
96
122
{
97
123
$ tag = @exec ('git describe --tags 2>&1 ' );
0 commit comments