Merge "Always use the canonical extension name when necessary"
[lhc/web/wiklou.git] / maintenance / validateRegistrationFile.php
1 <?php
2
3 require_once __DIR__ . '/Maintenance.php';
4
5 class ValidateRegistrationFile extends Maintenance {
6 public function __construct() {
7 parent::__construct();
8 $this->addArg( 'path', 'Path to extension.json/skin.json file.', true );
9 }
10 public function execute() {
11 if ( !class_exists( 'JsonSchema\Uri\UriRetriever' ) ) {
12 $this->error( 'The JsonSchema library cannot be found, please install it through composer.', 1 );
13 }
14
15 $retriever = new JsonSchema\Uri\UriRetriever();
16 $schema = $retriever->retrieve('file://' . dirname( __DIR__ ) . '/docs/extension.schema.json' );
17 $path = $this->getArg( 0 );
18 $data = json_decode( file_get_contents( $path ) );
19 if ( !is_object( $data ) ) {
20 $this->error( "$path is not a valid JSON file.", 1 );
21 }
22
23 $validator = new JsonSchema\Validator();
24 $validator->check( $data, $schema );
25 if ( $validator->isValid() ) {
26 $this->output( "$path validates against the schema!\n" );
27 } else {
28 foreach ( $validator->getErrors() as $error ) {
29 $this->output( "[{$error['property']}] {$error['message']}\n" );
30 }
31 $this->error( "$path does not validate.", 1 );
32 }
33 }
34 }
35
36 $maintClass = 'ValidateRegistrationFile';
37 require_once RUN_MAINTENANCE_IF_MAIN;