summaryrefslogtreecommitdiff
path: root/test/HTML5/Parser/EventStack.php
blob: 6f5576e48242e840d648ce8ba56e3e354acb1b4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
namespace HTML5\Parser;
require __DIR__ . '/../TestCase.php';

class EventStack implements EventHandler {
  protected $stack;

  public function __construct() {
    $this->stack = array();
  }

  /**
   * Get the event stack.
   */
  public function events() {
    return $this->stack;
  }

  public function depth() {
    return count($this->stack);
  }

  protected function store($event, $data = NULL) {
    $stack[] = array(
      'name' => $event,
      'data' => $data,
    );
  }

  public function doctype($name, $publicId, $systemID, $quirks) {
    $args = func_get_args();
    $this->store('doctype', $args);
  }

  public function startTag($name, $attributes = array(), $selfClosing = FALSE) {
    $args = func_get_args();
    $this->store('startTag', $args);
  }

  public function endTag($name) {
    $this->store('endTag', array($name));
  }

  public function comment($cdata) {
    $this->store('comment', array($cdata));
  }

  public function text($cdata) {
    $this->store('character', array($cdata));
  }

  public function eof() {
    $this->store('eof');
  }


}