Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
44.44% covered (danger)
44.44%
4 / 9
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
VisualEditorParsoidClientFactory
44.44% covered (danger)
44.44%
4 / 9
66.67% covered (warning)
66.67%
2 / 3
6.74
0.00% covered (danger)
0.00%
0 / 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%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 createDirectClient
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\Extension\VisualEditor;
4
5use MediaWiki\Context\RequestContext;
6use MediaWiki\Parser\Parsoid\Config\SiteConfig;
7use MediaWiki\Permissions\Authority;
8use MediaWiki\Rest\Handler\Helper\PageRestHelperFactory;
9
10/**
11 * @since 1.40
12 */
13class VisualEditorParsoidClientFactory {
14
15    /**
16     * @internal For use by ServiceWiring.php only or when locating the service
17     */
18    public const SERVICE_NAME = 'VisualEditor.ParsoidClientFactory';
19
20    public function __construct(
21        private readonly PageRestHelperFactory $pageRestHelperFactory,
22        private readonly SiteConfig $siteConfig,
23    ) {
24    }
25
26    /**
27     * Create a ParsoidClient for accessing Parsoid.
28     *
29     * @param string|string[]|false $cookiesToForward
30     * @param Authority|null $performer
31     *
32     * @return ParsoidClient
33     */
34    public function createParsoidClient(
35        /* Kept for compatibility with other extensions */ $cookiesToForward,
36        ?Authority $performer = null
37    ): ParsoidClient {
38        if ( $performer === null ) {
39            $performer = RequestContext::getMain()->getAuthority();
40        }
41
42        return $this->createDirectClient( $performer );
43    }
44
45    /**
46     * Create a ParsoidClient for accessing Parsoid.
47     */
48    private function createDirectClient( Authority $performer ): ParsoidClient {
49        return new DirectParsoidClient(
50            $this->pageRestHelperFactory,
51            $this->siteConfig,
52            $performer
53        );
54    }
55
56}