14
14
define ('TESTSCHEMA_VERSION ' , getopt ('v: ' )['v ' ]);
15
15
define ('SCHEMA_DIR ' , realpath (__DIR__ . '/../../../../schema ' ));
16
16
define ('SCHEMA_FILE ' , SCHEMA_DIR . '/bom- ' . TESTSCHEMA_VERSION . '.xsd ' );
17
+ define ('SPDX_FILE ' , SCHEMA_DIR . '/spdx.xsd ' );
18
+
17
19
define ('TESTDATA_DIR ' , realpath (__DIR__ . '/../resources/ ' . TESTSCHEMA_VERSION ));
18
20
19
21
if (empty (TESTSCHEMA_VERSION )) {
@@ -58,7 +60,13 @@ function validateFile(string $file): ?LibXMLError
58
60
throw new Exception ("failed loading file: $ file " . PHP_EOL . libxml_get_last_error ()->message );
59
61
}
60
62
61
- $ valid = $ doc ->schemaValidate (SCHEMA_FILE );
63
+ $ xsd = str_replace (
64
+ 'schemaLocation="http://cyclonedx.org/schema/spdx" ' ,
65
+ 'schemaLocation="file:// ' . htmlspecialchars (SPDX_FILE , ENT_XML1 , 'UTF-8 ' ) .'" ' ,
66
+ file_get_contents (SCHEMA_FILE )
67
+ );
68
+
69
+ $ valid = $ doc ->schemaValidateSource ($ xsd , LIBXML_SCHEMA_CREATE );
62
70
return $ valid
63
71
? null
64
72
: libxml_get_last_error ();
@@ -96,4 +104,4 @@ function validateFile(string $file): ?LibXMLError
96
104
97
105
// Exit statuses should be in the range 0 to 254, the exit status 255 is reserved by PHP and shall not be used.
98
106
// The status 0 is used to terminate the program successfully.
99
- exit (min ($ errCnt , 254 ));
107
+ exit (min ($ errCnt , 254 ));
0 commit comments