wiki.techinc.nl/maintenance/generateConfigSchemaArray.php
daniel 2fe23d6860 Use class constants to define config schema, rather than config-schema.yaml
Instead of maintaining the config schema as a yaml file, we
maintain it as a set of constants in a class. From the information in
these constants, we can generate a JSON schema (yaml) file, and an
php file containing optimized arrays for fast loading.

Advantages:
- PHP doc available to IDEs. The generated markdown file is no longer
  needed.
- Can use PHP constants when defining default values.

NOTE: needs backport to 1.38

Change-Id: I663c08b8a200644cbe7e5f65c20f1592a4f3974d
2022-03-17 21:20:03 +01:00

50 lines
1.2 KiB
PHP

<?php
use Wikimedia\StaticArrayWriter;
require_once __DIR__ . '/Maintenance.php';
require_once __DIR__ . '/includes/ConfigSchemaDerivativeTrait.php';
/**
* Maintenance script that generates the PHP representation of the config-schema.yaml file.
*
* @ingroup Maintenance
*/
class GenerateConfigSchemaArray extends Maintenance {
use ConfigSchemaDerivativeTrait;
/** @var string */
private const DEFAULT_OUTPUT_PATH = __DIR__ . '/../includes/config-schema.php';
public function __construct() {
parent::__construct();
$this->addDescription( 'Generate an optimized config-schema.php file.' );
$this->addOption(
'output',
'Path to output relative to $IP. Default: ' . self::DEFAULT_OUTPUT_PATH,
false,
true
);
}
public function execute() {
$schema = $this->loadSettingsSource();
foreach ( $schema['config-schema'] as $key => &$value ) {
unset( $value['description'] );
}
$content = ( new StaticArrayWriter() )->write(
$schema,
"This file is automatically generated using maintenance/generateConfigSchema.php.\n" .
"phpcs:disable Generic.Files.LineLength"
);
$this->writeOutput( self::DEFAULT_OUTPUT_PATH, $content );
}
}
$maintClass = GenerateConfigSchemaArray::class;
require_once RUN_MAINTENANCE_IF_MAIN;