Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
ParsoidClientFactory
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
3 / 3
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 createParsoidClient
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 createDirectClient
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace ContentTranslation;
4
5use MediaWiki\Rest\Handler\Helper\PageRestHelperFactory;
6use RequestContext;
7
8class ParsoidClientFactory {
9
10    /**
11     * @internal For use by ServiceWiring.php only or when locating the service
12     * @var string
13     */
14    public const SERVICE_NAME = 'ContentTranslation.ParsoidClientFactory';
15
16    /** @var PageRestHelperFactory */
17    private $pageRestHelperFactory;
18
19    /**
20     * @param PageRestHelperFactory $pageRestHelperFactory
21     */
22    public function __construct(
23        PageRestHelperFactory $pageRestHelperFactory
24    ) {
25        $this->pageRestHelperFactory = $pageRestHelperFactory;
26    }
27
28    /**
29     * Create a ParsoidClient for accessing Parsoid.
30     *
31     * @return ParsoidClient
32     */
33    public function createParsoidClient(): ParsoidClient {
34        return $this->createDirectClient();
35    }
36
37    /**
38     * Create a ParsoidClient for accessing Parsoid.
39     *
40     * @return ParsoidClient
41     */
42    private function createDirectClient(): ParsoidClient {
43        $performer = RequestContext::getMain()->getAuthority();
44        return new DirectParsoidClient( $this->pageRestHelperFactory, $performer );
45    }
46}