Debian Codegraph @

includes/OutputTransform/OutputTransformStage.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\OutputTransform;
4
5 use MediaWiki\Config\ServiceOptions;
6 use MediaWiki\Parser\ParserOptions;
7 use MediaWiki\Parser\ParserOutput;
8 use Psr\Log\LoggerInterface;
9
10 /**
11 * Classes implementing the OutputTransformStage aim at being added to a pipeline of transformations that transform
12 * a ParserOutput. The argument ParserOutput can explicitly be modified in place; ensuring that cached objects
13 * do not suffer from side effects is the caller's (typically the pipeline's) responsibility.
14 * @unstable
15 */
16 abstract class OutputTransformStage {
17 protected ServiceOptions $options;
18 protected LoggerInterface $logger;
19
20 /** @internal */
21 public const CONSTRUCTOR_OPTIONS = [];
22
23 /** @internal */
24 public function __construct( ServiceOptions $options, LoggerInterface $logger ) {
25 // Note this is static:: not self:: so we use the subclass options
26 $options->assertRequiredOptions( static::CONSTRUCTOR_OPTIONS );
27 $this->options = $options;
28 $this->logger = $logger;
29 }
30
31 /**
32 * Decides whether or not the stage should be run
33 * @param ParserOutput $po
34 * @unstable
35 * @param ParserOptions|null $popts
36 * @param array $options
37 * @return bool
38 */
39 abstract public function shouldRun( ParserOutput $po, ?ParserOptions $popts, array $options = [] ): bool;
40
41 /**
42 * Transforms the input ParserOutput into the returned ParserOutput.
43 * The returned ParserOutput can explicitly be a modified version of the input ParserOutput; if modifications
44 * to that object are unexpected, a copy should be made before passing it to this method.
45 * TODO Some transformations require the possibility of modifying options (this is the case of
46 * ExecutePostCacheTransformHooks in particular). We do NOT want to keep this mechanism for later versions of
47 * this interface - the currently foreseen goal is to not pass $options at all.
48 * Modifying $options during this pass is considered deprecated.
49 * @unstable
50 */
51 abstract public function transform( ParserOutput $po, ?ParserOptions $popts, array &$options ): ParserOutput;
52 }