mediawiki-extensions-Visual.../includes/VisualEditorParsoidClientFactory.php
thiemowmde 1d449787ef Add type declarations and remove redundant PHPDoc tags
Most of this code was already typed, but not everything. Using
language-level type declarations allows us to remove extra PHPDoc
blocks that just repeat the same information.

I'm also using the more narrow UserIdentity instead of User in a
few places where this is possible.

Change-Id: I7661824fcb34180af1a4fd3030fcd6c0b7d34089
2024-06-04 16:55:00 +00:00

57 lines
1.3 KiB
PHP

<?php
namespace MediaWiki\Extension\VisualEditor;
use MediaWiki\Permissions\Authority;
use MediaWiki\Rest\Handler\Helper\PageRestHelperFactory;
use RequestContext;
/**
* @since 1.40
*/
class VisualEditorParsoidClientFactory {
/**
* @internal For use by ServiceWiring.php only or when locating the service
*/
public const SERVICE_NAME = 'VisualEditor.ParsoidClientFactory';
private PageRestHelperFactory $pageRestHelperFactory;
public function __construct(
PageRestHelperFactory $pageRestHelperFactory
) {
$this->pageRestHelperFactory = $pageRestHelperFactory;
}
/**
* Create a ParsoidClient for accessing Parsoid.
*
* @param string|string[]|false $cookiesToForward
* @param Authority|null $performer
*
* @return ParsoidClient
*/
public function createParsoidClient(
/* Kept for compatibility with other extensions */ $cookiesToForward,
?Authority $performer = null
): ParsoidClient {
if ( $performer === null ) {
$performer = RequestContext::getMain()->getAuthority();
}
return $this->createDirectClient( $performer );
}
/**
* Create a ParsoidClient for accessing Parsoid.
*/
private function createDirectClient( Authority $performer ): ParsoidClient {
return new DirectParsoidClient(
$this->pageRestHelperFactory,
$performer
);
}
}