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\Context\RequestContext;
6use MediaWiki\Permissions\Authority;
7use MediaWiki\Rest\Handler\Helper\PageRestHelperFactory;
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     */
17    public const SERVICE_NAME = 'VisualEditor.ParsoidClientFactory';
18
19    public function __construct(
20        private readonly PageRestHelperFactory $pageRestHelperFactory,
21    ) {
22    }
23
24    /**
25     * Create a ParsoidClient for accessing Parsoid.
26     *
27     * @param string|string[]|false $cookiesToForward
28     * @param Authority|null $performer
29     *
30     * @return ParsoidClient
31     */
32    public function createParsoidClient(
33        /* Kept for compatibility with other extensions */ $cookiesToForward,
34        ?Authority $performer = null
35    ): ParsoidClient {
36        if ( $performer === null ) {
37            $performer = RequestContext::getMain()->getAuthority();
38        }
39
40        return $this->createDirectClient( $performer );
41    }
42
43    /**
44     * Create a ParsoidClient for accessing Parsoid.
45     */
46    private function createDirectClient( Authority $performer ): ParsoidClient {
47        return new DirectParsoidClient(
48            $this->pageRestHelperFactory,
49            $performer
50        );
51    }
52
53}