Debian Codegraph @

vendor/wikimedia/remex-html/src/Tokenizer/TokenGeneratorHandler.php

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