Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 13 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
JsonSchemaVersionManager | |
0.00% |
0 / 13 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getClassPrefix | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
getVersionForSchema | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\CommunityConfiguration\Schema; |
4 | |
5 | class JsonSchemaVersionManager implements SchemaVersionManager { |
6 | |
7 | private const VERSIONS_NAMESPACE = 'Migrations'; |
8 | |
9 | private JsonSchemaReader $jsonSchema; |
10 | |
11 | public function __construct( JsonSchemaReader $jsonSchema ) { |
12 | $this->jsonSchema = $jsonSchema; |
13 | } |
14 | |
15 | private function getClassPrefix(): string { |
16 | $classNameParts = explode( '\\', $this->jsonSchema->getReflectionClass()->getName() ); |
17 | $baseName = implode( |
18 | '\\', |
19 | array_slice( $classNameParts, 0, count( $classNameParts ) - 1 ) |
20 | ); |
21 | $schemaName = end( $classNameParts ); |
22 | |
23 | return $baseName . '\\' . self::VERSIONS_NAMESPACE . '\\' . $schemaName . '_'; |
24 | } |
25 | |
26 | /** |
27 | * @inheritDoc |
28 | * @return JsonSchemaReader |
29 | */ |
30 | public function getVersionForSchema( string $version ): SchemaReader { |
31 | if ( $version == $this->jsonSchema->getVersion() ) { |
32 | return $this->jsonSchema; |
33 | } |
34 | |
35 | return new JsonSchemaReader( |
36 | $this->getClassPrefix() . str_replace( '.', '_', $version ) |
37 | ); |
38 | } |
39 | } |