Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 41 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
| TokenGeneratorHandler | |
0.00% |
0 / 41 |
|
0.00% |
0 / 8 |
72 | |
0.00% |
0 / 1 |
| startDocument | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| endDocument | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| error | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| characters | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
| startTag | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
| endTag | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| doctype | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| comment | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | declare( strict_types = 1 ); |
| 3 | |
| 4 | namespace Wikimedia\RemexHtml\Tokenizer; |
| 5 | |
| 6 | /** |
| 7 | * The handler which converts events to tokens arrays for TokenGenerator |
| 8 | */ |
| 9 | class TokenGeneratorHandler implements TokenHandler { |
| 10 | /** @var array[] */ |
| 11 | public $tokens = []; |
| 12 | |
| 13 | /** @inheritDoc */ |
| 14 | public function startDocument( Tokenizer $tokenizer, $fragmentNamespace, $fragmentName ) { |
| 15 | $this->tokens[] = [ |
| 16 | 'type' => 'startDocument', |
| 17 | 'fragmentNamespace' => $fragmentNamespace, |
| 18 | 'fragmentName' => $fragmentName |
| 19 | ]; |
| 20 | } |
| 21 | |
| 22 | /** @inheritDoc */ |
| 23 | public function endDocument( $pos ) { |
| 24 | $this->tokens[] = [ 'type' => 'endDocument' ]; |
| 25 | } |
| 26 | |
| 27 | /** @inheritDoc */ |
| 28 | public function error( $text, $pos ) { |
| 29 | $this->tokens[] = [ |
| 30 | 'type' => 'error', |
| 31 | 'text' => $text, |
| 32 | 'sourceStart' => $pos |
| 33 | ]; |
| 34 | } |
| 35 | |
| 36 | /** @inheritDoc */ |
| 37 | public function characters( $text, $start, $length, $sourceStart, $sourceLength ) { |
| 38 | $this->tokens[] = [ |
| 39 | 'type' => 'text', |
| 40 | 'text' => $text, |
| 41 | 'start' => $start, |
| 42 | 'length' => $length, |
| 43 | 'sourceStart' => $sourceStart, |
| 44 | 'sourceLength' => $sourceLength ]; |
| 45 | } |
| 46 | |
| 47 | /** @inheritDoc */ |
| 48 | public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) { |
| 49 | $this->tokens[] = [ |
| 50 | 'type' => 'startTag', |
| 51 | 'name' => $name, |
| 52 | 'attrs' => $attrs, |
| 53 | 'selfClose' => $selfClose, |
| 54 | 'sourceStart' => $sourceStart, |
| 55 | 'sourceLength' => $sourceLength ]; |
| 56 | } |
| 57 | |
| 58 | /** @inheritDoc */ |
| 59 | public function endTag( $name, $sourceStart, $sourceLength ) { |
| 60 | $this->tokens[] = [ |
| 61 | 'type' => 'endTag', |
| 62 | 'name' => $name, |
| 63 | 'sourceStart' => $sourceStart, |
| 64 | 'sourceLength' => $sourceLength ]; |
| 65 | } |
| 66 | |
| 67 | /** @inheritDoc */ |
| 68 | public function doctype( $name, $public, $system, $quirks, $sourceStart, $sourceLength ) { |
| 69 | $this->tokens[] = [ |
| 70 | 'type' => 'doctype', |
| 71 | 'name' => $name, |
| 72 | 'public' => $public, |
| 73 | 'system' => $system, |
| 74 | 'quirks' => $quirks ]; |
| 75 | } |
| 76 | |
| 77 | /** @inheritDoc */ |
| 78 | public function comment( $text, $sourceStart, $sourceLength ) { |
| 79 | $this->tokens[] = [ |
| 80 | 'type' => 'comment', |
| 81 | 'text' => $text, |
| 82 | 'sourceStart' => $sourceStart, |
| 83 | 'sourceLength' => $sourceLength ]; |
| 84 | } |
| 85 | } |