Security update for Core, with self-updated composer
[yaffs-website] / vendor / masterminds / html5 / test / HTML5 / Parser / EventStack.php
1 <?php
2 namespace Masterminds\HTML5\Tests\Parser;
3
4 use Masterminds\HTML5\Elements;
5 use Masterminds\HTML5\Parser\EventHandler;
6
7 /**
8  * This testing class gathers events from a parser and builds a stack of events.
9  * It is useful for checking the output of a tokenizer.
10  *
11  * IMPORTANT:
12  *
13  * The startTag event also kicks the parser into TEXT_RAW when it encounters
14  * script or pre tags. This is to match the behavior required by the HTML5 spec,
15  * which says that the tree builder must tell the tokenizer when to switch states.
16  */
17 class EventStack implements EventHandler
18 {
19
20     protected $stack;
21
22     public function __construct()
23     {
24         $this->stack = array();
25     }
26
27     /**
28      * Get the event stack.
29      */
30     public function events()
31     {
32         return $this->stack;
33     }
34
35     public function depth()
36     {
37         return count($this->stack);
38     }
39
40     public function get($index)
41     {
42         return $this->stack[$index];
43     }
44
45     protected function store($event, $data = null)
46     {
47         $this->stack[] = array(
48             'name' => $event,
49             'data' => $data
50         );
51     }
52
53     public function doctype($name, $type = 0, $id = null, $quirks = false)
54     {
55         $args = array(
56             $name,
57             $type,
58             $id,
59             $quirks
60         );
61         $this->store('doctype', $args);
62     }
63
64     public function startTag($name, $attributes = array(), $selfClosing = false)
65     {
66         $args = func_get_args();
67         $this->store('startTag', $args);
68         if ($name == 'pre' || $name == 'script') {
69             return Elements::TEXT_RAW;
70         }
71     }
72
73     public function endTag($name)
74     {
75         $this->store('endTag', array(
76             $name
77         ));
78     }
79
80     public function comment($cdata)
81     {
82         $this->store('comment', array(
83             $cdata
84         ));
85     }
86
87     public function cdata($data)
88     {
89         $this->store('cdata', func_get_args());
90     }
91
92     public function text($cdata)
93     {
94         // fprintf(STDOUT, "Received TEXT event with: " . $cdata);
95         $this->store('text', array(
96             $cdata
97         ));
98     }
99
100     public function eof()
101     {
102         $this->store('eof');
103     }
104
105     public function parseError($msg, $line, $col)
106     {
107         // throw new EventStackParseError(sprintf("%s (line %d, col %d)", $msg, $line, $col));
108         // $this->store(sprintf("%s (line %d, col %d)", $msg, $line, $col));
109         $this->store('error', func_get_args());
110     }
111
112     public function processingInstruction($name, $data = null)
113     {
114         $this->store('pi', func_get_args());
115     }
116 }