MediaWiki master
GrammarTransformations.php
Go to the documentation of this file.
1<?php
6
7namespace Wikimedia\Leximorph\Provider;
8
9use Wikimedia\Leximorph\Util\JsonLoader;
10
21
25 private const string TRANSFORMATIONS_PATH = __DIR__ . '/../data/grammarTransformations/';
26
32 private static array $transformationsCache = [];
33
37 public function __construct(
38 private readonly string $langCode,
39 private readonly JsonLoader $jsonLoader,
40 ) {
41 }
42
49 public function getTransformations(): array {
50 self::$transformationsCache ??= [];
51
52 if ( isset( self::$transformationsCache[$this->langCode] ) ) {
53 return self::$transformationsCache[$this->langCode];
54 }
55
56 $filePath = self::TRANSFORMATIONS_PATH . $this->langCode . '.json';
57 $transformations = $this->jsonLoader->load( $filePath, 'grammar transformations' );
58
59 self::$transformationsCache[$this->langCode] = $transformations;
60
62 }
63}