View source
<?php
namespace Masterminds\HTML5\Tests\Parser;
use Masterminds\HTML5\Elements;
use Masterminds\HTML5\Parser\EventHandler;
class EventStack implements EventHandler {
protected $stack;
public function __construct() {
$this->stack = array();
}
public function events() {
return $this->stack;
}
public function depth() {
return count($this->stack);
}
public function get($index) {
return $this->stack[$index];
}
protected function store($event, $data = null) {
$this->stack[] = array(
'name' => $event,
'data' => $data,
);
}
public function doctype($name, $type = 0, $id = null, $quirks = false) {
$args = array(
$name,
$type,
$id,
$quirks,
);
$this
->store('doctype', $args);
}
public function startTag($name, $attributes = array(), $selfClosing = false) {
$args = func_get_args();
$this
->store('startTag', $args);
if ($name == 'pre' || $name == 'script') {
return Elements::TEXT_RAW;
}
}
public function endTag($name) {
$this
->store('endTag', array(
$name,
));
}
public function comment($cdata) {
$this
->store('comment', array(
$cdata,
));
}
public function cdata($data) {
$this
->store('cdata', func_get_args());
}
public function text($cdata) {
$this
->store('text', array(
$cdata,
));
}
public function eof() {
$this
->store('eof');
}
public function parseError($msg, $line, $col) {
$this
->store('error', func_get_args());
}
public function processingInstruction($name, $data = null) {
$this
->store('pi', func_get_args());
}
}