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