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