Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
TranslationUnitStoreFactory
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 3
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getReader
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 getWriter
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\PageTranslation;
5
6use LogicException;
7use MediaWiki\Page\PageIdentity;
8use Wikimedia\Rdbms\ILoadBalancer;
9use const DB_PRIMARY;
10use const DB_REPLICA;
11
12/**
13 * @author Niklas Laxström
14 * @license GPL-2.0-or-later
15 * @since 2021.05
16 */
17class TranslationUnitStoreFactory {
18    private ILoadBalancer $lb;
19
20    public function __construct( ILoadBalancer $lb ) {
21        $this->lb = $lb;
22    }
23
24    public function getReader( PageIdentity $page ): TranslationUnitReader {
25        $pageId = $page->getId();
26        if ( $pageId === 0 ) {
27            throw new LogicException( 'Page must exist' );
28        }
29
30        return new TranslationUnitStore( $this->lb->getConnection( DB_REPLICA ), $pageId );
31    }
32
33    public function getWriter( PageIdentity $page ): TranslationUnitStore {
34        $pageId = $page->getId();
35        if ( $pageId === 0 ) {
36            throw new LogicException( 'Page must exist' );
37        }
38
39        return new TranslationUnitStore( $this->lb->getConnection( DB_PRIMARY ), $pageId );
40    }
41}