24require_once __DIR__ .
'/../includes/Benchmarker.php';
35 parent::__construct();
36 $this->addDescription(
'Benchmarks JsonCodec.' );
39 'A json file, or a php file that returns a data structure. Default is config-schema.php',
45 'Whether JSON objects should be represented as associative arrays when loading'
50 $file = $this->getOption(
'file', MW_INSTALL_PATH .
'/includes/config-schema.php' );
51 $data = $this->loadData( $file );
52 $bytes = json_encode( $data );
57 "JsonCodec::serialize ($file)" => [
58 'function' =>
static function (
JsonCodec $codec, $data ) {
61 'args' => [ $codec, $data ]
63 "JsonCodec::deserialize ($file)" => [
64 'function' =>
static function (
JsonCodec $codec, $bytes ) {
67 'args' => [ $codec, $bytes ]
69 "JsonCodec::detectNonSerializableData ($file)" => [
70 'function' =>
static function (
JsonCodec $codec, $data ) {
73 'args' => [ $codec, $data ]
78 private function loadData( $file ) {
79 if ( str_ends_with( $file,
'.php' ) ) {
80 $data = include $file;
82 $this->fatalError(
"Failed to load data from " . $file );
87 $raw = $this->loadFile( $file );
88 $data = json_decode( $raw, $this->getOption(
'assoc',
false ) );
91 $this->fatalError(
"Failed to load data from " . $file );
100require_once RUN_MAINTENANCE_IF_MAIN;