Debian Codegraph @

extensions/VisualEditor/includes/VisualEditorParsoidClientFactory.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Extension\VisualEditor;
4
5 use MediaWiki\Context\RequestContext;
6 use MediaWiki\Permissions\Authority;
7 use MediaWiki\Rest\Handler\Helper\PageRestHelperFactory;
8
9 /**
10 * @since 1.40
11 */
12 class 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 private PageRestHelperFactory $pageRestHelperFactory;
20
21 public function __construct(
22 PageRestHelperFactory $pageRestHelperFactory
23 ) {
24 $this->pageRestHelperFactory = $pageRestHelperFactory;
25 }
26
27 /**
28 * Create a ParsoidClient for accessing Parsoid.
29 *
30 * @param string|string[]|false $cookiesToForward
31 * @param Authority|null $performer
32 *
33 * @return ParsoidClient
34 */
35 public function createParsoidClient(
36 /* Kept for compatibility with other extensions */ $cookiesToForward,
37 ?Authority $performer = null
38 ): ParsoidClient {
39 if ( $performer === null ) {
40 $performer = RequestContext::getMain()->getAuthority();
41 }
42
43 return $this->createDirectClient( $performer );
44 }
45
46 /**
47 * Create a ParsoidClient for accessing Parsoid.
48 */
49 private function createDirectClient( Authority $performer ): ParsoidClient {
50 return new DirectParsoidClient(
51 $this->pageRestHelperFactory,
52 $performer
53 );
54 }
55
56 }