| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
use MediaWiki\MainConfigSchema; |
| 25 |
use MediaWiki\Registration\ExtensionRegistry; |
| 26 |
use MediaWiki\Settings\Config\ArrayConfigBuilder; |
| 27 |
use MediaWiki\Settings\Config\NullIniSink; |
| 28 |
use MediaWiki\Settings\SettingsBuilder; |
| 29 |
use MediaWiki\Settings\Source\PhpSettingsSource; |
| 30 |
use MediaWiki\Settings\Source\ReflectionSchemaSource; |
| 31 |
|
| 32 |
|
| 33 |
require_once __DIR__ . '/../includes/Benchmarker.php'; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
class BenchmarkSettings extends Benchmarker { |
| 42 |
public function __construct() { |
| 43 |
parent::__construct(); |
| 44 |
$this->defaultCount = 100; |
| 45 |
$this->addDescription( 'Benchmark loading settings files.' ); |
| 46 |
} |
| 47 |
|
| 48 |
private function newSettingsBuilder() { |
| 49 |
$extReg = new ExtensionRegistry(); |
| 50 |
$configBuilder = new ArrayConfigBuilder(); |
| 51 |
$phpIniSink = new NullIniSink(); |
| 52 |
return new SettingsBuilder( MW_INSTALL_PATH, $extReg, $configBuilder, $phpIniSink, null ); |
| 53 |
} |
| 54 |
|
| 55 |
public function execute() { |
| 56 |
$benches = []; |
| 57 |
|
| 58 |
$schemaSource = new ReflectionSchemaSource( MainConfigSchema::class ); |
| 59 |
$schema = $schemaSource->load(); |
| 60 |
$defaults = []; |
| 61 |
|
| 62 |
foreach ( $schema['config-schema'] as $key => $sch ) { |
| 63 |
if ( array_key_exists( 'default', $sch ) ) { |
| 64 |
$defaults[$key] = $sch['default']; |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
$benches['DefaultSettings.php'] = [ |
| 69 |
'setup' => static function () { |
| 70 |
|
| 71 |
include MW_INSTALL_PATH . '/includes/DefaultSettings.php'; |
| 72 |
}, |
| 73 |
'function' => static function () { |
| 74 |
include MW_INSTALL_PATH . '/includes/DefaultSettings.php'; |
| 75 |
} |
| 76 |
]; |
| 77 |
|
| 78 |
$benches['config-schema.php'] = [ |
| 79 |
'function' => function () { |
| 80 |
$settingsBuilder = $this->newSettingsBuilder(); |
| 81 |
$settingsBuilder->load( |
| 82 |
new PhpSettingsSource( MW_INSTALL_PATH . '/includes/config-schema.php' ) |
| 83 |
); |
| 84 |
$settingsBuilder->apply(); |
| 85 |
} |
| 86 |
]; |
| 87 |
|
| 88 |
$benches['config-schema.php + merge'] = [ |
| 89 |
'function' => function () use ( $defaults ) { |
| 90 |
$settingsBuilder = $this->newSettingsBuilder(); |
| 91 |
|
| 92 |
|
| 93 |
$settingsBuilder->loadArray( [ 'config' => $defaults ] ); |
| 94 |
$settingsBuilder->load( |
| 95 |
new PhpSettingsSource( MW_INSTALL_PATH . '/includes/config-schema.php' ) |
| 96 |
); |
| 97 |
$settingsBuilder->apply(); |
| 98 |
} |
| 99 |
]; |
| 100 |
|
| 101 |
$benches['MainConfigSchema::class'] = [ |
| 102 |
'function' => function () { |
| 103 |
$settingsBuilder = $this->newSettingsBuilder(); |
| 104 |
$settingsBuilder->load( new ReflectionSchemaSource( MainConfigSchema::class ) ); |
| 105 |
$settingsBuilder->apply(); |
| 106 |
} |
| 107 |
]; |
| 108 |
|
| 109 |
$benches['DefaultSettings.php + SetupDynamicConfig.php'] = [ |
| 110 |
'function' => static function () { |
| 111 |
$IP = MW_INSTALL_PATH; |
| 112 |
include MW_INSTALL_PATH . '/includes/DefaultSettings.php'; |
| 113 |
|
| 114 |
|
| 115 |
$wgLocaltimezone = 'utc'; |
| 116 |
include MW_INSTALL_PATH . '/includes/SetupDynamicConfig.php'; |
| 117 |
} |
| 118 |
]; |
| 119 |
|
| 120 |
$benches['config-schema.php + finalize'] = [ |
| 121 |
'function' => function () { |
| 122 |
$settingsBuilder = $this->newSettingsBuilder(); |
| 123 |
$settingsBuilder->load( |
| 124 |
new PhpSettingsSource( MW_INSTALL_PATH . '/includes/config-schema.php' ) |
| 125 |
); |
| 126 |
$settingsBuilder->enterRegistrationStage(); |
| 127 |
|
| 128 |
|
| 129 |
extract( $GLOBALS ); |
| 130 |
|
| 131 |
|
| 132 |
$wgDummyLanguageCodes = []; |
| 133 |
include MW_INSTALL_PATH . '/includes/SetupDynamicConfig.php'; |
| 134 |
} |
| 135 |
]; |
| 136 |
|
| 137 |
$this->bench( $benches ); |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
$maintClass = BenchmarkSettings::class; |
| 143 |
require_once RUN_MAINTENANCE_IF_MAIN; |
| 144 |
|