Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 6 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| TokenHandler | |
0.00% |
0 / 6 |
|
0.00% |
0 / 4 |
20 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| setPipelineId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| resetState | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| isDisabled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| process | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| 1 | <?php |
| 2 | declare( strict_types = 1 ); |
| 3 | |
| 4 | namespace Wikimedia\Parsoid\Wt2Html\TT; |
| 5 | |
| 6 | use Wikimedia\Parsoid\Config\Env; |
| 7 | use Wikimedia\Parsoid\Tokens\Token; |
| 8 | use Wikimedia\Parsoid\Wt2Html\TokenHandlerPipeline; |
| 9 | |
| 10 | abstract class TokenHandler { |
| 11 | protected Env $env; |
| 12 | protected TokenHandlerPipeline $manager; |
| 13 | protected ?int $pipelineId; |
| 14 | protected array $options; |
| 15 | /** This is set if the token handler is disabled for the entire pipeline. */ |
| 16 | protected bool $disabled = false; |
| 17 | /** |
| 18 | * This is set/reset by the token handlers at various points in the token stream based on what |
| 19 | * is encountered. This only enables/disables the onAny handler. |
| 20 | */ |
| 21 | protected bool $atTopLevel = false; |
| 22 | |
| 23 | /** |
| 24 | * @param TokenHandlerPipeline $manager The manager for this stage of the parse. |
| 25 | * @param array $options Any options for the expander. |
| 26 | */ |
| 27 | public function __construct( TokenHandlerPipeline $manager, array $options ) { |
| 28 | $this->manager = $manager; |
| 29 | $this->env = $manager->getEnv(); |
| 30 | $this->options = $options; |
| 31 | } |
| 32 | |
| 33 | public function setPipelineId( int $id ): void { |
| 34 | $this->pipelineId = $id; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Resets any internal state for this token handler. |
| 39 | * |
| 40 | * @param array $options |
| 41 | */ |
| 42 | public function resetState( array $options ): void { |
| 43 | $this->atTopLevel = $options['toplevel'] ?? false; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Is this transformer disabled? |
| 48 | * @return bool |
| 49 | */ |
| 50 | public function isDisabled(): bool { |
| 51 | return $this->disabled; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Push an input array of tokens through the handler |
| 56 | * and return a new array of transformed tokens. |
| 57 | * |
| 58 | * @param array<string|Token> $tokens |
| 59 | * @return array<string|Token> |
| 60 | */ |
| 61 | abstract public function process( array $tokens ): array; |
| 62 | } |