summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/Maps/src/Presentation/OutputFacade.php
blob: 119f3b1df5b7844c0a9a27581a6903126d5caf78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php

namespace Maps\Presentation;

use OutputPage;
use ParserOutput;

class OutputFacade {

	/**
	 * @var OutputPage
	 */
	private $outputPage;

	/**
	 * @var ParserOutput
	 */
	private $parserOutput;

	public static function newFromOutputPage( OutputPage $outputPage ) {
		$instance = new self();
		$instance->outputPage = $outputPage;
		return $instance;
	}

	public static function newFromParserOutput( ParserOutput $parserOutput ) {
		$instance = new self();
		$instance->parserOutput = $parserOutput;
		return $instance;
	}

	public function addHtml( string $html ) {
		if ( $this->outputPage !== null ) {
			$this->outputPage->addHTML( $html );
		}

		if ( $this->parserOutput !== null ) {
			$this->parserOutput->setText( $this->parserOutput->getRawText() . $html );
		}
	}

	public function addModules( string ...$modules ) {
		if ( $this->outputPage !== null ) {
			$this->outputPage->addModules( $modules );
		}

		if ( $this->parserOutput !== null ) {
			$this->parserOutput->addModules( $modules );
		}
	}

	public function addHeadItem( string $name, string $html ) {
		if ( $this->outputPage !== null ) {
			$this->outputPage->addHeadItem( $name, $html );
		}

		if ( $this->parserOutput !== null ) {
			$this->parserOutput->addHeadItem( $html, $name );
		}
	}

}