You are here

class EventStack in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/masterminds/html5/test/HTML5/Parser/EventStack.php \Masterminds\HTML5\Tests\Parser\EventStack

This testing class gathers events from a parser and builds a stack of events. It is useful for checking the output of a tokenizer.

IMPORTANT:

The startTag event also kicks the parser into TEXT_RAW when it encounters script or pre tags. This is to match the behavior required by the HTML5 spec, which says that the tree builder must tell the tokenizer when to switch states.

Hierarchy

Expanded class hierarchy of EventStack

File

vendor/masterminds/html5/test/HTML5/Parser/EventStack.php, line 17

Namespace

Masterminds\HTML5\Tests\Parser
View source
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);
  }
  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) {

    // fprintf(STDOUT, "Received TEXT event with: " . $cdata);
    $this
      ->store('text', array(
      $cdata,
    ));
  }
  public function eof() {
    $this
      ->store('eof');
  }
  public function parseError($msg, $line, $col) {

    // throw new EventStackParseError(sprintf("%s (line %d, col %d)", $msg, $line, $col));
    // $this->store(sprintf("%s (line %d, col %d)", $msg, $line, $col));
    $this
      ->store('error', func_get_args());
  }
  public function processingInstruction($name, $data = null) {
    $this
      ->store('pi', func_get_args());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EventHandler::DOCTYPE_NONE constant
EventHandler::DOCTYPE_PUBLIC constant
EventHandler::DOCTYPE_SYSTEM constant
EventStack::$stack protected property
EventStack::cdata public function A CDATA section. Overrides EventHandler::cdata
EventStack::comment public function A comment section (unparsed character data). Overrides EventHandler::comment
EventStack::depth public function
EventStack::doctype public function A doctype declaration. Overrides EventHandler::doctype
EventStack::endTag public function An end-tag. Overrides EventHandler::endTag
EventStack::eof public function Indicates that the document has been entirely processed. Overrides EventHandler::eof
EventStack::events public function Get the event stack.
EventStack::get public function
EventStack::parseError public function Emitted when the parser encounters an error condition. Overrides EventHandler::parseError
EventStack::processingInstruction public function This is a holdover from the XML spec. Overrides EventHandler::processingInstruction
EventStack::startTag public function A start tag. Overrides EventHandler::startTag
EventStack::store protected function
EventStack::text public function A unit of parsed character data. Overrides EventHandler::text
EventStack::__construct public function