47 if ( !class_exists( Validator::class ) ) {
48 call_user_func( $this->missingDepCallback,
49 'The JsonSchema library cannot be found, please install it through composer.'
52 } elseif ( !class_exists( SpdxLicenses::class ) ) {
53 call_user_func( $this->missingDepCallback,
54 'The spdx-licenses library cannot be found, please install it through composer.'
68 $data = json_decode( file_get_contents( $path ) );
69 if ( !is_object( $data ) ) {
73 if ( !isset( $data->manifest_version ) ) {
75 "$path does not have manifest_version set." );
78 $version = $data->manifest_version;
79 $schemaPath = __DIR__ .
"/../../docs/extension.schema.v$version.json";
84 "$path is using a non-supported schema version"
88 "$path is using a non-supported schema version"
92 $licenseError =
false;
94 if ( isset( $data->{
'license-name'} ) && is_string( $data->{
'license-name'} ) ) {
95 $licenses =
new SpdxLicenses();
96 $valid = $licenses->validate( $data->{
'license-name'} );
98 $licenseError =
'[license-name] Invalid SPDX license identifier, '
99 .
'see <https://spdx.org/licenses/>';
103 $validator =
new Validator;
104 $validator->check( $data, (
object)[
'$ref' =>
'file://' . $schemaPath ] );
105 if ( $validator->isValid() && !$licenseError ) {
109 $out =
"$path did not pass validation.\n";
110 foreach ( $validator->getErrors() as $error ) {
111 $out .=
"[{$error['property']}] {$error['message']}\n";
113 if ( $licenseError ) {
114 $out .=
"$licenseError\n";