Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 22
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
ConfiguredLexiconStorage
0.00% covered (danger)
0.00%
0 / 22
0.00% covered (danger)
0.00%
0 / 5
110
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
42
 getEntry
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 createEntryItem
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 updateEntryItem
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 deleteEntryItem
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\Wikispeech\Lexicon;
4
5/**
6 * @file
7 * @ingroup Extensions
8 * @license GPL-2.0-or-later
9 */
10
11use MediaWiki\MediaWikiServices;
12use MediaWiki\Wikispeech\WikispeechServices;
13use MWException;
14
15/**
16 * A decorated {@link LexiconStorage}
17 * selected based on the configuration value WikispeechPronunciationLexiconConfiguration
18 * @since 0.1.9
19 */
20class ConfiguredLexiconStorage implements LexiconStorage {
21
22    /** @var LexiconStorage */
23    private $decorated;
24
25    /**
26     * @since 0.1.9
27     * @param string $enumValue
28     * @param MediaWikiServices $services
29     * @throws MWException If value of WikispeechPronunciationLexiconConfiguration is unsupported.
30     */
31    public function __construct(
32        string $enumValue,
33        MediaWikiServices $services
34    ) {
35        $enumValueLower = trim( mb_strtolower( $enumValue ) );
36        if ( $enumValueLower === 'speechoid' ) {
37            $this->decorated = WikispeechServices::getLexiconSpeechoidStorage( $services );
38        } elseif ( $enumValueLower === 'wiki' ) {
39            $this->decorated = WikispeechServices::getLexiconWikiStorage( $services );
40        } elseif ( $enumValueLower === 'wiki+speechoid' ) {
41            $this->decorated = new LexiconHandler(
42                WikispeechServices::getLexiconSpeechoidStorage( $services ),
43                WikispeechServices::getLexiconWikiStorage( $services )
44            );
45        } elseif ( $enumValueLower === 'cache' ) {
46            $this->decorated = WikispeechServices::getLexiconWanCacheStorage( $services );
47        } elseif ( $enumValueLower === 'cache+speechoid' ) {
48            $this->decorated = new LexiconHandler(
49                WikispeechServices::getLexiconSpeechoidStorage( $services ),
50                WikispeechServices::getLexiconWanCacheStorage( $services )
51            );
52        } else {
53            throw new MWException( "Unsupported value for WikispeechPronunciationLexiconConfiguration: $enumValue" );
54        }
55    }
56
57    /**
58     * @inheritDoc
59     */
60    public function getEntry(
61        string $language,
62        string $key
63    ): ?LexiconEntry {
64        return $this->decorated->getEntry( $language, $key );
65    }
66
67    /**
68     * @inheritDoc
69     */
70    public function createEntryItem(
71        string $language,
72        string $key,
73        LexiconEntryItem $item
74    ): void {
75        $this->decorated->createEntryItem( $language, $key, $item );
76    }
77
78    /**
79     * @inheritDoc
80     */
81    public function updateEntryItem(
82        string $language,
83        string $key,
84        LexiconEntryItem $item
85    ): void {
86        $this->decorated->updateEntryItem( $language, $key, $item );
87    }
88
89    /**
90     * @inheritDoc
91     */
92    public function deleteEntryItem(
93        string $language,
94        string $key,
95        LexiconEntryItem $item
96    ): void {
97        $this->decorated->deleteEntryItem( $language, $key, $item );
98    }
99}